[英]Grunt switch task between dev and prod
I have a grunt file I am trying to see if I can split so I can call something like grunt build:dev
or grunt build:prod
. 我有一个grunt文件,我试图看看我是否可以拆分,所以我可以调用像grunt build:dev
或grunt build:prod
。
Right now the task looks like this - 现在任务看起来像这样 -
grunt.registerTask('build', "Building all needed files.", [
'clean:build',
'check-code',
'clean:dist',
'dist:prepare',
'copy',
'cssmin',
'injector',
'webpack:prod',
'create-status-page'
]);
And I am wondering if there is a way to split this task like you can with configs with a key of dev
and prod
, where the task list for prod it slight different than dev. 我想知道是否有一种方法可以像使用dev
和prod
的密钥一样分配这个任务,其中prod
的任务列表与dev略有不同。 Sort of similiar to how you might do it with tha configs like 有点类似于你如何使用像这样的配置
return {
dev: {
...
},
prod: {
...
}
}
Is something like this possible? 这样的事情可能吗? To be clear, I am asking if I can get away with registering both these in a single task. 要清楚,我问我是否可以在一项任务中注册这两项。
You may be able to use a multitask . 您可以使用多任务 。
grunt.initConfig({
build: {
dev: ['task1', 'task2', 'task3'],
prod: ['taskA', 'taskB', 'taskC']
}
});
grunt.registerMultiTask('build', 'Building...', function() {
grunt.task.run(this.data);
});
Then you can do grunt build:dev
or grunt build:prod
然后你可以做grunt build:dev
或grunt build:prod
Note: If you just do grunt build
, it will iterate through all of the properties, so it would run both dev tasks and prod tasks. 注意:如果你只是进行grunt build
,它将遍历所有属性,因此它将运行dev任务和prod任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.