繁体   English   中英

获取Grunt插件的目标

[英]Get a Grunt plugin's target

我正在构建一个Grunt插件,并且需要在Gruntfile.js选择一个目标。

Gruntfile.js:

grunt.initConfig({
    plugin: {
        options: {},
        target: {}  // <= This is what I want to select
    }
});

task / plugin.js内部,我可以使用options = this.options()来获取options对象,但是我不能只使用this.target 有什么想法吗?

Grunt仅针对多任务公开this.target 要访问定时任务( 在相同的值grunt foo:bar ),访问args数组代替: this.args[0]

更新:

先前的答案是根据Grunt的官方术语写的。 重新阅读您的问题,您将使用grunt.config()方法访问config对象中的属性,并 grunt.config()研究您要在grunt config对象中尝试访问的特定属性。 基于上面的grunt.initConfig ,您可以使用grunt.config('plugin.target');访问target的内容grunt.config('plugin.target');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM