所以,我使用grunt-require构建了我的RequireJS应用程序,我相信在幕后使用r.js。但是,在运行应用程序时,我每次都会这样做:
Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded require-2.1.9.min.js:8
GET http://localhost:8080/resources/js/app/App.js 404 (Not Found) require-2.1.9.min.js:34
Uncaught Error: Script error for: app/App
http://requirejs.org/docs/errors.html#scripterror
我的“主要”脚本位于app / Main.js中,如下所示:
require(['common'], function() {
'use strict';
require(['app/App'], function(app) {
app.start();
});
});
然后是grunt-require的构建选项:
requirejs: {
options: {
baseUrl: 'resources/js',
dir: 'resources/js/build',
main: 'app/Main',
out: null,
optimize: 'uglify2',
skipDirOptimize: true,
priority: ['common'],
preserveLicenseComments: false,
modules: [
{
name: 'common'
},{
name: 'app/Main',
exclude: ['common'],
include: ['app/App']
}
],
paths: { ... },
shim: { ... }
}
}
正如您所看到的,我在app / Main.js的构建中包含了app / App。
它按预期分别加载Main.js和common.js,但之后它会尝试单独加载app / App.js。当我查看Main.js的内置版本时,我发现app / App.js实际上是内置的。
为什么它试图单独加载app / App.js的任何想法?