注册自定义 grunt 任务时,我可以循环访问另一个任务的目标吗?



如果我正在创建自定义的grunt任务,它可以遍历另一个任务的目标吗?假设我的 initConfig 中有这个:

    clean: {
        target1: {
            // etc etc
        },
        target1: {
            // etc etc
        }
    }

并且我正在注册一个任务:

grunt.registerTask('deploy', function() {
    var run = [];
    // Loop through the targets in 'clean', comparing them 
    // with details passed in in my arguments array...
    grunt.task.run(run);
});

我本质上想查询任务中的目标,并动态构建要运行的内容数组。

谢谢

托比

有几个选项:http://gruntjs.com/api/grunt.config

grunt.config

从项目的 Grunt 配置中获取或设置一个值。此方法 用作其他方法的别名;如果传递两个参数, grunt.config.set 被调用,否则调用 grunt.config.get。

grunt.config([prop [, value]])

grunt.config.get

从项目的 Grunt 配置中获取一个值。如果道具是 指定,则返回该属性的值,如果该属性,则返回 null 未定义。如果未指定 prop,则整个配置的副本 返回对象。模板字符串将被递归处理 使用 grunt.config.process 方法。

grunt.config.get([prop])

相关内容

最新更新