根据RequireJS API,bundles
配置属性用于将模块映射到其捆绑文件(在生产模式下,假设您在大型项目中有多个捆绑包)。
我当然使用Grunt捆绑r.js
,如何根据实际捆绑动态生成bundle
配置?例如如果模块angular
已绑定到common.js
,则应将其添加到common
包的模块列表中。
这部分requirejs配置不应该手动维护,因为它会导致许多错误。
有什么建议吗?
答案 0 :(得分:1)
RequireJS 2.2.0版引入了new optimizer option来写出从构建中生成的bundles
选项:
//Introduced in 2.2.0. Path to file to write out bundles config
//(http://requirejs.org/docs/api.html#config-bundles) found in the module
//layers built by the optimizer. The path is relative to the "dir" config's
//path. Only applies to full project optimization:
//http://requirejs.org/docs/optimization.html#wholeproject
//Only use if the optimized layers are grouped more intricately then just
//a simple optimization of main app entry points. The file path specified
//should be to one that has the top level requirejs.config() call that sets
//up the loader. If using "mainConfigFile", then this path likely should be
//the path to that file where it is placed in the "dir" output directory.
bundlesConfigOutFile: 'some/path/to/main.js',
如果上述选项对您不起作用,那么您必须执行我所做的操作并滚动您自己的代码以生成bundles
的正确值。