Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
    }
}
like image 523
user2565123 Avatar asked Mar 20 '14 16:03

user2565123


People also ask

Can we configure Grunt to run one or more tasks by default by defining a default task?

Custom tasksYou can configure Grunt to run one or more tasks by default by defining a default task. In the following example, running grunt at the command line without specifying a task will run the uglify task. This is functionally the same as explicitly running grunt uglify or even grunt default .

When a task is run Grunt looks for its configuration under a?

When a task is run, Grunt looks for its configuration under a property of the same name. Multi-tasks can have multiple configurations, defined using arbitrarily named "targets." In the example below, the concat task has foo and bar targets, while the uglify task only has a bar target.

Which Grunt plugin is used to run predefined tasks when the watched file changes?

grunt-este-watchby Daniel SteigerwaldRun predefined tasks whenever watched file changes.

How do you check if a task exist in Grunt?

Check with the name, if a task exists in the registered tasks.


1 Answers

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
like image 60
jgillich Avatar answered Sep 22 '22 14:09

jgillich