【问题标题】:Running multiple Grunt tasks of the same task type运行多个相同任务类型的 Grunt 任务
【发布时间】:2014-03-20 16:46:10
【问题描述】:

我需要能够在 Grunt (grunt-contrib-concat) 中运行多个相同类型的任务。我在下面尝试了几件事,但都没有工作。对如何做到这一点的任何想法表示赞赏。

concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js',
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

和..

concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    }
},
concat: {
    dist: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

和..

concat: {
    dist: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    },
    dist: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

【问题讨论】:

标签: gruntjs grunt-contrib-concat


【解决方案1】:

首先为任务定义两个目标:

concat: {
    dist1: {
        src: [
            'js/foo1/bar1.js',
            'js/foo1/bar2.js'
        ],
        dest: 'js/foo1.js'
    },
    dist2: {
        src: [
            'js/foo2/bar1.js',
            'js/foo2/bar2.js'
        ],
        dest: 'js/foo2.js'
    }
}

然后注册一个同时运行的新任务:

grunt.registerTask('dist', ['concat:dist1', 'concat:dist2']);

然后运行

grunt dist

【讨论】:

  • 一些 grunt 插件(例如 grunt-phpunit)不支持目标。见github.com/SaschaGalley/grunt-phpunit/issues/27
  • 我发现保持我的监视任务不变(如 [concat])也有效 - 它自动通过 dist1 和 dist2
  • 嗨,我有这个错误,正在验证配置中存在 concat.dist1 属性...错误
  • 你能帮帮我吗?
  • @Angu 请提交一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-23
  • 2016-10-02
  • 1970-01-01
  • 1970-01-01
  • 2014-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多