我正在构建一个 Grunt 插件,我需要选择 Gruntfile.js
中的目标之一。
Gruntfile.js:
grunt.initConfig({
plugin: {
options: {},
target: {} // <= This is what I want to select
}
});
在 tasks/plugin.js 内部,我可以使用 options = this.options()
来获取 options
对象,但我可以不只是使用 this.target
。有什么想法吗?
最佳答案
Grunt 仅公开 multi-tasks 的 this.target
。要为常规任务访问相同的值(grunt foo:bar
中的bar),请访问 args array相反:this.args[0]
更新:
之前的回答是按照Grunt官方术语写的。重新阅读你的问题,你会 access the property within the config object使用 grunt.config()
方法,深入了解您尝试在 grunt 配置对象中访问的特定属性。根据上面的 grunt.initConfig
,您可以使用 grunt.config('plugin.target');
访问 target
的内容/p>
关于javascript - 获取 Grunt 插件的目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36660524/