以编程方式为grunt任务设置选项? [英] Programmatically set options for grunt task?

查看:96
本文介绍了以编程方式为grunt任务设置选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个咕task任务,用 grunt.option('foo')来查看选项。如果我从 grunt.task.run('my-task')调用这个任务,我该如何改变这些参数?



我正在寻找类似的东西:

  grunt.task.run('my-task', {foo:'bar'}); 

这相当于:

 $ grunt my-task --foo'bar'

这可能吗?



这个问题是我遇到的另一个问题,但并不完全相同,因为在这种情况下,我无法访问原始任务的Gruntfile.js。)

  grunt.option( 'foo','bar'); 
grunt.task.run('my-task');

在全局范围内设置选项而不仅仅是该命令会感觉有点奇怪,但它起作用。

I have a grunt task that looks at options with grunt.option('foo'). If I'm calling this task from grunt.task.run('my-task'), how can I change those arguments?

I'm looking for something like:

grunt.task.run('my-task', {foo: 'bar'});

which would be the equivalent of:

$ grunt my-task --foo 'bar'

Is this possible?

(This question is another issue I ran in to but is not exactly the same, because in this case I don't have access to the original task's Gruntfile.js.)

解决方案

Looks like I can use the following:

grunt.option('foo', 'bar');
grunt.task.run('my-task');

It feels a bit odd to set the options globally instead of just for that command, but it works.

这篇关于以编程方式为grunt任务设置选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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