Running multiple Grunt tasks of the same task type
Asked Answered
A

1

10

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'
    }
}
Afterbirth answered 20/3, 2014 at 16:46 Comment(1)
My question is answered here: #21918702Afterbirth
W
35

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
Westbrooks answered 20/3, 2014 at 17:3 Comment(6)
Some of the grunt plugins (ex grunt-phpunit) do not support targets. See github.com/SaschaGalley/grunt-phpunit/issues/27Swinney
I found that keeping my watch task unchanged (as [concat]) worked too - it automatically went through both dist1 and dist2Tyranny
hi , i have this error, Verifying property concat.dist1 exists in config...ERRORUnlikelihood
Can you help anyone for me?Unlikelihood
@Unlikelihood Please submit a new question.Westbrooks
@Westbrooks .. can you check my question? stackoverflow.com/questions/36424008/how-to-use-grunt-concatUnlikelihood

© 2022 - 2024 — McMap. All rights reserved.