我无法bundles
在优化的构建中工作,我正在尝试加载一些外部预构建包(不包含在需要构建过程输出中)。
在requirejs.config
:
paths: {
'mymodules': '../lib/test-bundle/test-bundle'
},
bundles: {
'mymodules': ['mymodule1', 'mymodule2']
}
test-bundle
内容是:
console.log("defining modules...");
define('mymodule1', ['jquery'], function($) {
console.log('within mymodule1', $.fn.jquery);
return {
test: 'module1'
};
});
define('mymodule2', ['jquery'], function($) {
console.log('within mymodule2', $.fn.jquery);
return {
test: 'module2'
};
});
在构建配置 paths
中mymodules
,mymodule1
并mymodule2
设置为empty:
(或构建过程失败),我没有使用构建配置modules
中的选项来生成捆绑包。
如果我按原样使用源,那么一切正常,正如预期的那样。
在构建版本(但未优化)test-bundle
中加载并"defining modules"
打印,然后超时加载mymodule2
:
Error: Failed to load root module (viewmodels/shell). Details: Load timeout for modules: mymodule2(…)
Uncaught Error: Failed to load root module (viewmodels/shell). Details: Load timeout for modules: mymodule2
http://requirejs.org/docs/errors.html#timeout
在构建和优化的版本中,还有一个错误:
Uncaught ReferenceError: define is not defined
就像 if在implementtest-bundle
之前加载。requirejs
define()
我错过了什么或做错了什么?
编辑
我已经使用上面的测试创建了一个分支来安装和构建(nodejs
npm
并且可能grunt-cli
在系统上是必需的)
git clone https://github.com/xenogenesi/HTMLStarterKitPro
cd HTMLStarterKitPro
git checkout test-bundle
# nodejs npm required on the system (maybe grunt-cli)
npm install # required only once to install node modules
grunt build-only # create a build/ directory and the content
php -S localhost:8888 # to publish the sources as they are
# browse to http://localhost:8888
php -S localhost:7777 -t build # to publish the built versions
# browse to http://localhost:7777 for built but not optimized
# browse to http://localhost:7777/index2.html for built optimized
(请参阅此提交以获取所有修改以添加测试包的文件)