在运行时将选项传递给一个咕task任务 [英] Pass Options to a grunt task while running it

查看:76
本文介绍了在运行时将选项传递给一个咕task任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为有一种方法可以做到这一点,而我之前曾经偶然发现过。
我已阅读这些答案,但他们不是我所说的:

以编程方式将参数传递给grunt任务?

垃圾条件选项



从咕噜模板访问流程/环境



我也看了一下grunt docs,但它不在那里:

https://github.com/gruntjs/grunt/wiki/Configuring-tasks



是有这样的语法?

$ b grunt.task.run'htmlmin:allFiles:collapseWhitespace = true'
/ code>

解决您可以使用该语法,但它意味着将这些参数传递给htmlmin任务: 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?

Grunt conditional option

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, running grunt deploy --target=staging on the command line would cause grunt.option('target') to return "staging".

这篇关于在运行时将选项传递给一个咕task任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆