除了@Alessandro Pezzato酒店
Gruntfile.js:
grunt.registerTask('build', ['clean:dist', 'assemble', 'compass:dist', 'cssmin', 'copy:main']);
grunt.registerTask('build-prod', 'Build with production options', function() {
grunt.config.set('assemble.options.production', true);
grunt.task.run('build');
});
grunt.registerTask('build-live', 'Build with production options', function() {
grunt.option('assemble.options.production', false);
grunt.task.run('build');
});
现在你可以运行
$ grunt build-prod
- 或 -
$ grunt build-live
他们都将做充分的任务,“建设”和A值传递给options of assemble之一,即生产“真”或“假”。
除了说明组装例如多一点:
在组装必须添加一个{{#if production}}do this on production{{else}}do this not non production{{/if}}
如果你需要运行2个或多个任务,它将不起作用:/如果你有一个循环并设置'grunt.option'和'grunt.task.run',这两个任务都会运行在最后一次迭代的'grunt .option'; @Rosarch,你知道如何解决它吗? – 2014-04-22 22:27:57
@RafaelVerger您可以创建两个任务,一个负责运行任务,另一个负责更改选项。按交替顺序排列任务,并且它们将在正确设置选项的情况下运行。 – rosswil 2014-05-29 04:27:37
如果您有一套有限的选项,但是当你动态地获得这些选项时(例如使用MySQL查询服务器的发现)它将不起作用 – 2014-06-02 15:29:35