【发布时间】:2012-09-13 11:29:22
【问题描述】:
我的 main 中有一个 require.config,如下所示。
require.config({
baseUrl:'scripts/',paths:{ jquery:'shell/lib/jquery/jquery-1.7.1' // many libraries and modules are aliased here }, map:{ '*':{ 'underscore':'shell/lib/underscore/underscore' // a few other modules are mapped here } }});
我这样做是因为 map 中定义的文件使用相对路径的内部依赖项(在它们各自的文件夹中)。 现在,当我运行优化器时,路径中定义的模块保存为模块 ID,例如保存为 jquery 的 jquery,而映射中的模块正在获取完整路径,例如 'underscore' 为 'shell/lib/underscore/下划线”而不是“下划线”。
这会导致问题,因为我也在其他模块中使用“下划线”,并且优化后的文件有“下划线”而不是“shell/lib/underscore/underscore”。
当我们提供地图配置或我缺少的东西时,是否有一些特定的优化方法?请告诉我如何解决它。
谢谢
【问题讨论】:
-
不太清楚您为什么要尝试将下划线放入地图中。当您的应用程序中的不同模块依赖于不同版本的 Underscore 时,地图很有用。如果您的所有应用程序都依赖于一个版本的 Underscore,请将其输入路径。请在 cmets 中澄清,我会尽力帮助您。
-
这个下划线是写在下划线库上的一个包装器 .js 文件,上面写着 require[("./underscore-1.3.3").... 这样做是因为一个团队测试并定义了哪个开源库使用和其他团队使用它们。在编写像 Animation.js 这样的开源库的自定义扩展时,也会使用这种实现。提前致谢。
标签: javascript optimization module requirejs