我有一个使用 underscore.js 模板并通过 require.js + 文本插件加载它们的应用程序:
define([..., 'text!templates/app/authentication.html'], function(..., Template) {
...
});
一切正常,但现在我要通过 Grunt.js 和 require.js 优化器将我所有的 js 文件连接到一个文件中。以下是 grunt 文件中的相应部分:
requirejs: {
compile: {
options: {
name : 'main',
baseUrl: "www/js",
optimize: "none",
out: "www/js/result.js",
stubModules : ['text'],
paths : {
text: 'vendor/text',
...
},
shim: {
...
}
}
}
}
但是 grunt 抛出下一个错误:
Running "requirejs:compile" (requirejs) task
>> Tracing dependencies for: nexusapp
>> Error: ENOENT, no such file or directory
>> 'D:\templates\app\authentication.html'
>> In module tree:
>> main
>> app
>> app.authentication
>> text
Warning: RequireJS failed. Use --force to continue.
Aborted due to warnings.
优化器正在尝试读取忽略指定 baseUrl
的文件。
我该如何解决这个问题?
提前致谢!
最佳答案
我知道要从 RequireJS 编译中排除一个模块,您需要在配置文件中为其路径指定“empty:”。像这样:
{
...
...
paths: {
'module_you_want_1': '/path/to/module/you/want/1',
'module_you_want_2': '/path/to/module/you/want/2',
'module_you_dont_want': 'empty:'
},
...
...
}
关于javascript - 从 requirejs 优化中排除模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19316461/