我的第一篇文章,请多多指教^^
我正在使用 Grunt 和 load-grunt-config 将我的任务设置拆分为多个文件,如果我使用这种设置,则效果很好:
./Gruntfile.js:
module.exports = function(grunt) {
var path = require('path');
var myParam = grunt.option('myParam') || 'responsive';
// Project configuration.
grunt.initConfig({
...
require('load-grunt-config')(grunt);
...
});
...
};
./grunt/concat.js:
var conf = require('../mytheme.config.json');
module.exports = {
dist: {
src: conf.theme.js.src,
dest: conf.theme.js.dist + 'mytheme.bundle.js',
options: {
}
}
};
我的问题如下:如何将“myParam”变量传递给“concat.js”文件中的外部配置?
我不明白如何使用https://github.com/creynders/load-grunt-configs中的文档来做到这一点
谢谢
最佳答案
好吧,我发现了一些对我有用的东西:
./Gruntfile.js
module.exports = function(grunt) {
// Define
var myParam = grunt.option('myParam') || 'responsive';
// Plugins
require('time-grunt')(grunt);
require('jit-grunt')(grunt);
require('load-grunt-config')(grunt, {
configPath: path.join(process.cwd(), 'grunt/config'),
jitGrunt: {
customTasksDir: 'grunt/tasks'
},
data: {
myParam: myParam // accessible with '<%= myParam %>'
}
});
};
./grunt/config/concat.js
var conf = require('../../mytheme.config.json');
module.exports = {
dist: {
src: conf.theme.js.src,
dest: conf.theme.js.dist + '<%= myParam %>/mytheme.bundle.js',
options: {
}
}
};
希望它也能帮助别人。
关于javascript - 如何使用 load-grunt-config 将参数传递给外部文件中定义的 grunt 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39975053/