tl;博士
RequireJS 优化器不喜欢我在模块上定义包定义,但如果我不定义包,也找不到模块。
长版
尝试使用 requirejs 优化器时出现以下错误:
Error: Module loading did not complete for: scripts/simulation.bundle, app_mini, testservice
The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module in it:
.../web/dist/scripts/app.bundle.js: app_mini, testservice
我实际上正在使用 grunt-contrib-requirejs 来优化我的 js 脚本以进行生产。在添加之前一切正常simulator.bundle
我有 3 个捆绑包:
- app.bundle(主包)
- 模拟.bundle
- 供应商.bundle
这是modules
requirejs grunt 任务的选项
[{
name: 'scripts/vendor.bundle',
exclude: [],
override: {
paths: {
angular: 'bower/angular/angular',
jquery: 'bower/jquery/dist/jquery',
ngRoute: "bower/angular-route/angular-route"
},
shim: {
angular: {
exports: 'angular',
deps: ['jquery'] // make jquery dependency - angular will replace jquery lite with full jquery
},
bundles: {
'scripts/app.bundle': ['app_mini', 'testservice'],
},
}
}
},
{
name: 'scripts/simulation.bundle',
exclude: [],
override: {
paths: {},
shim: {},
bundles: {
'scripts/vendor.bundle': ['angular', 'jquery'],
'scripts/app.bundle': ['app_mini', 'testservice']
}
}
},
{
name: 'scripts/app.bundle',
exclude: ['scripts/vendor.bundle'],
override: {
paths: {
app_mini: 'scripts/app.mini',
testservice: 'scripts/features/test.service'
},
shim: {},
bundles: {
'scripts/vendor.bundle': ['angular', 'jquery']
}
}
}
]
中的捆绑包simulation.bundle
似乎是问题所在。但是,如果我删除它们,则找不到文件:
>> Error: ENOENT: no such file or directory, open
>> '...\web\dist\app_mini.js'
>> In module tree:
>> scripts/simulation.bundle
这simulation.bundle
只是一个虚拟模块,加载angular
和app_mini
:
define(['app_mini', 'angular'], function(app_mini, angular) {
// nothing here
}
所以无论哪种方式,优化器都无法处理依赖关系。我必须如何配置它才能使其工作?