在运行时将选项传递给一个咕task任务 [英] Pass Options to a grunt task while running it
问题描述
我已阅读这些答案,但他们不是我所说的:
我也看了一下grunt docs,但它不在那里:
https://github.com/gruntjs/grunt/wiki/Configuring-tasks
是有这样的语法?
$ b grunt.task.run'htmlmin:allFiles:collapseWhitespace = true'
/ code>
allFiles
,'collapse = true'
。 例如,给定以下任务:
grunt.registerTask('so',function(arg1,arg2){
console.log(arg1 +,+ arg2);
});
运行:
grunt so:barley:test = true
提供以下输出:
barley,test = true
还有其他方法可以传递常见问题中描述的参数/共享信息:如何在多个任务之间共享参数?
- 选项可能适用于您
跨多个任务共享参数的另一种方法是要使用
grunt.option
。在这个例子中,在命令行上运行grunt deploy --target = staging
会导致grunt.option('target')
返回分期。
I thought there was a way to do this, and that I'd stumbled on it before. I have read these answers but they're not what I'm talking about:
Programmatically pass arguments to grunt task?
Accessing the process / environment from a grunt template
I also looked at the grunt docs but it isn't there:
https://github.com/gruntjs/grunt/wiki/Configuring-tasks
Is there a syntax like this?
grunt.task.run 'htmlmin:allFiles:collapseWhitespace=true'
You can use that syntax but it means pass these arguments to the htmlmin task: allFiles
, 'collapse=true'
.
For example, given the following task:
grunt.registerTask('so', function(arg1, arg2) {
console.log(arg1 + ", " + arg2);
});
Running:
grunt so:barley:test=true
Gives the following output:
barley, test=true
There are other ways to pass parameters/share info described in the faq: How can I share parameters across multiple tasks?
--Options may be applicable to you
Another way to share a parameter across multiple tasks would be to use
grunt.option
. In this example, runninggrunt deploy --target=staging
on the command line would causegrunt.option('target')
to return "staging".
这篇关于在运行时将选项传递给一个咕task任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!