簡體   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