以编程方式将参数传递给grunt任务? [英] Programmatically pass arguments to grunt task?
问题描述
我有一个叫做其他咕噜任务的咕task任务。我想用编程确定的参数调用子任务。这可能吗?我花了一些时间仔细研究 lib / grunt.js 和 lib / grunt / task.js ,但无法弄清楚。
I have a grunt task that calls other grunt tasks. I want to call a subtask with programmatically determined arguments. Is this possible? I spent some time digging around the lib/grunt.js and lib/grunt/task.js, but couldn't figure it out.
我使用 Gruntfile.js 中指定的以下参数使用 grunt-compass
:
I'm using grunt-compass
with the following arguments specified in Gruntfile.js:
compass: {
default_options: {
src: 'components/201',
dest: 'build',
require: ['zurb-foundation']
}
}
我希望能够在运行时覆盖它们:
I want to be able to override them at runtime:
tasks / my-task.js :
// simplified example
module.exports = function(grunt) {
grunt.registerTask('foo', 'bar', function() {
var chooseDest = doWork();
grunt.task.run('compass', {src: 'src', dest: chooseDest});
});
};
供参考:
For reference:
$ grunt --version
grunt-cli v0.1.6
grunt v0.4.0rc6
推荐答案
我明白了。在Gruntfile.js中使用<%=%>
语法:
I figured it out. Use the <%= %>
syntax in Gruntfile.js:
compass: {
default_options: {
src: 'components/<%= myTask.src %>',
dest: 'build',
require: ['zurb-foundation']
}
}
然后您可以设置它在你的任务中:
Then you can set it in your task:
grunt.config.set('myTask.src', getSrc());
这篇关于以编程方式将参数传递给grunt任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!