更新时间:2023-08-25 23:34:40
这些都在 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');