运行相同任务类型的多个Grunt任务

use*_*123 9 gruntjs grunt-contrib-concat

我需要能够在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'
    }
}
Run Code Online (Sandbox Code Playgroud)

和..

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'
    }
}
Run Code Online (Sandbox Code Playgroud)

和..

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'
    }
}
Run Code Online (Sandbox Code Playgroud)

jgi*_*ich 32

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

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'
    }
}
Run Code Online (Sandbox Code Playgroud)

然后注册一个运行两者的新任务:

grunt.registerTask('dist', ['concat:dist1', 'concat:dist2']);
Run Code Online (Sandbox Code Playgroud)

然后运行

grunt dist
Run Code Online (Sandbox Code Playgroud)