当我使用 r.js 构建项目时(我是通过 grunt 完成的,但我离题了),它会丑化并压缩项目的所有 javascript 文件并将它们包含在构建文件夹中,即使所有这些文件已被压缩为单个 JavaScript 文件,并且不再以其单独的形式使用。
我正在使用模块,因此我无法使用“out”标志,因为它不兼容。我正在使用 grunt-contrib-clean 来清理所有额外的文件,但如果我能够避免首先包含它们,那就太理想了。
这是我的 grunt options.js:
module.exports = {
appDir: 'src',
baseUrl: 'js/',
mainConfigFile: 'src/js/common.js',
dir: 'www',
modules: [
{
name: 'common',
include: [
'jquery',
'underscore',
'handlebars',
'hbs',
'i18nprecompile',
'json2',
'Class'
]
},
{
name: 'app/page1',
exclude: ['common']
},
{
name: 'app/page2',
exclude: ['common']
}
]
};
当它构建时,它包含 lib 文件夹中的所有文件(当唯一需要的文件是 require.js 时),并且它包含由 page1 和 page2 导入的所有 javascript 文件的丑化版本,即使所有这些文件都已被合并为page1.js和page2.js。
我是否遗漏了一些东西,或者构建后清理只是生活中的一个事实?
最佳答案
可以通过将 removeCombined
设置为 false 来简单地修复它:
//If set to true, any files that were combined into a build layer will be
//removed from the output folder.
removeCombined: false,
有关任何其他构建选项的深入详细信息 can be found in this example file .
关于requirejs - 如何防止 requirejs 包含所有源文件而只包含模块文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13615093/