我的 Gruntfile 现在变得非常大,我想将它分成多个文件。我用 Google 搜索并进行了很多试验,但无法让它发挥作用。
我想要这样的东西:
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
concat: getConcatConfiguration()
});
}
函数.js
function getConcatConfiguration() {
// Do some stuff to generate and return configuration
}
如何将 functions.js 加载到我的 Gruntfile.js 中?
最佳答案
如何做到:
你需要导出你的 concat 配置,并在你的 Gruntfile 中要求它(基本的 node.js 东西)!
我建议将所有特定于任务的配置放入一个以配置命名的文件中(在这种情况下,我将其命名为 concat.js
)。
此外,我将 concat.js
移到了名为 grunt
的文件夹中
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
concat: require('grunt/concat')(grunt);
});
};
咕噜声/concat.js
module.exports = function getConcatConfiguration(grunt) {
// Do some stuff to generate and return configuration
};
你应该怎么做:
那里已经有人创建了一个名为 load-grunt-config 的模块.这正是您想要的。
继续将所有内容(如上所述)放入单独的文件中,放入您选择的位置(默认文件夹 ist grunt
)。
那么你的标准 gruntfile 应该看起来像这样:
module.exports = function(grunt) {
require('load-grunt-config')(grunt);
// define some alias tasks here
};
关于javascript - 拆分 Gruntfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356538/