Grunt命令行参数 [英] Grunt Command Line Parameters
问题描述
我有一个Grunt构建文件。我的构建文件的任务如下所示:
myTask:{
options:{
configFile:config / default.js,
args:{}
},
dev:{
configFile:'config / local.js',
options :{args:{}},
},
test:{
configFile:'config / remote.js',
options:{args:{}}
$ / code $ / pre
$ p
grunt.registerTask('customTask',['myTask:dev']);
grunt.registerTask('customTask-Test',['myTask:test']);
目前,我可以从命令行运行以下命令:
> grunt customTask
一切正常。但是,我需要添加这样的功能:
> grunt customTask --myParam = myValue
我需要在dev中查看myParam的值,任务目标。但是,我无法弄清楚如何去做。
如果我可以在运行myTask:dev时打印出myParam的值,我会很高兴。换句话说,
我想在运行时看到以下内容:
> grunt customTask
> grunt customTask --myParam = hello
您输入了hello
> grunt customTask-Test
> grunt customTask-Test --myParam = hello
我该如何做这样的事情?
解决方案这些都在 grunt.option 页面。
您的情况可以通过以下方式获得 myParam
的值:
var target = grunt.option('myParam');
I have a Grunt build file. My build file has a task that looks like the following:
myTask: {
options: {
configFile: "config/default.js",
args: { }
},
dev: {
configFile: 'config/local.js',
options: { args: {} },
},
test: {
configFile: 'config/remote.js',
options: { args: {} }
}
}
...
grunt.registerTask('customTask', ['myTask:dev']);
grunt.registerTask('customTask-Test', ['myTask:test']);
Currently, I can run the following from the command line:
> grunt customTask
Everything works fine. However, I need to add the ability to do something like this:
> grunt customTask --myParam=myValue
I need to look at the value of myParam in my "dev" task target. However, I can't figure out how to do it.
I would be happy if I could just print out the value of myParam when myTask:dev is ran. In other words,
I'd like to see the following when run
> grunt customTask
> grunt customTask --myParam=hello
You entered hello
> grunt customTask-Test
> grunt customTask-Test --myParam=hello
How do I do something like this?
解决方案 This is all explained in the grunt.option page.
In your case, you could get the value of myParam
with:
var target = grunt.option('myParam');
这篇关于Grunt命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!