Search code examples
gruntjsgrunt-contrib-concat

Running multiple Grunt tasks of the same task type


I need to be able to run multiple tasks of the same type of task within Grunt (grunt-contrib-concat). I've tried a couple of things below but neither work. Any ideas on how to do this are appreciated.

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'
    }
}

and..

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'
    }
}

and..

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'
    }
}

Solution

  • First define two targets for the task:

    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'
        }
    }
    

    Then register a new task that runs both:

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

    Then run using

    grunt dist