Javascript 在grunt插件中,如何获得全局和目标特定选项的组合,该选项为';什么是数组?
我正在写一个grunt插件,它有可以是值数组的选项。具体而言,这些值是文件(与任务本身的“文件”属性中指定的文件不同)。我的任务设置可以如下所示:Javascript 在grunt插件中,如何获得全局和目标特定选项的组合,该选项为';什么是数组?,javascript,node.js,plugins,gruntjs,Javascript,Node.js,Plugins,Gruntjs,我正在写一个grunt插件,它有可以是值数组的选项。具体而言,这些值是文件(与任务本身的“文件”属性中指定的文件不同)。我的任务设置可以如下所示: grunt.initConfig({ assemble: { options: { data: ['test/common/data/common1.json', 'test/common/data/common2.json'] }, dev: { options: {
grunt.initConfig({
assemble: {
options: {
data: ['test/common/data/common1.json', 'test/common/data/common2.json']
},
dev: {
options: {
data: ['test/dev/data/dev.json']
},
files: {
'test/actual': ['test/files/dev.hbs']
}
},
prod: {
options: {
data: ['test/prod/data/prod.json']
},
files: {
'test/actual': ['test/files/prod.hbs']
}
},
}
});
在我的插件中,我希望能够使用全局选项和目标选项中指定的所有文件的列表来获取数据选项
对于开发目标grunt assembly:dev
我将在this.options.data
['test/common/data/common1.json',
'test/common/data/common2.json',
'test/dev/data/dev.json']
['test/common/data/common1.json',
'test/common/data/common2.json',
'test/prod/data/prod.json']
对于prod目标grunt assemble:prod
我将在this.options.data
['test/common/data/common1.json',
'test/common/data/common2.json',
'test/dev/data/dev.json']
['test/common/data/common1.json',
'test/common/data/common2.json',
'test/prod/data/prod.json']
我已经找到了解决这个问题的方法,但我不确定这是否是最好的选择 在我的插件中,我可以通过
grunt.config
方法访问全局和特定于目标的选项
var globalDataFiles = grunt.config(['assemble', 'options', 'data']) || [];
var targetDataFiles = grunt.config(['assemble', this.target, 'options', 'data']) || [];
使用lodash<代码>变量=要求('lodash')代码>
我可以合并阵列:
var data = _.union(globalDataFiles, targetDataFiles);
我在我的插件中对此做了更多的工作,但这就是我最初解决这个问题的方式
请查看所有代码。您好,解决了完全相同的问题。。。你找到更好的解决办法了吗?我想手动访问目标选项中的常用选项:选项:模式:grunt.config(['replace','options','patterns']).concat([