javascript - 获取 Grunt 插件的目标

标签 javascript gruntjs

我正在构建一个 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-tasksthis.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/

相关文章:

javascript - 来自 mainConfigFile 的 RequireJS 优化器不工作

gruntjs - 遍历 yeoman 中的子目录并组装

javascript - 使用 JavaScript 在搜索栏中的词序

javascript - 有没有办法使用 javascript 来增加时间?

javascript - 按钮禁用,除非两个输入字段都有值

node.js - Windows 8 上的咕噜声 : 'grunt' is not recognized

javascript - 如何在不同的文件上使用不同的 grunt-contrib-less 选项

javascript - Grunt Connect 服务器 CSS 文件为空

javascript - 使用 javascript 进行表单检查

javascript - imacros javascript 条件 eval 语句