VKS
VKS

Reputation: 277

Adding a task with in a task in a gruntfile

I have gruntfile as below:

       concat: {
        options: {
            banner: '<%= banner %>',
            stripBanners: true
        },
        one: {
            src: ['src/**/*.js'],
            dest: 'dist/<%= pkg.name %>_ac.js'
        },

        two: {
            src: ['/types/**/*.js'],
            dest: 'dist/<%= pkg.name %>_lib.js'
        },

        all: {
        }
    },.....  and so on

Now if i register the task like: grunt.registerTask('basic', ['concat:all']);

I want both one and two to run. How shall i add this option in

     all: {
          // what i need to add here to include one and two both?
     }

Upvotes: 0

Views: 512

Answers (3)

Sheba
Sheba

Reputation: 736

You can use 'gruntfile' plugin where you are provided with more powerful functionality and you can add tasks of one grunt file to another using concat.

Refer the link : https://github.com/shama/gruntfile

Upvotes: 1

kds
kds

Reputation: 28665

Grunt allow you to define the main target. So in your default target define as

grunt.registerTask( 'basic',['concat']);

This will activate the concat:one and concat:two.

If you need to activate a specific target, define your register task as follows.

    grunt.registerTask( 'basic',['concat:one']);

If you need to run the specific task which has multiple targets then you can define as follows.

all: {
     tasks: ['one','two']
    }

Then in your registerTask call the all target.

 grunt.registerTask( 'basic',['concat:all']);

Hope this might help.

Upvotes: 2

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

No need to add another target if you're registering a task to point to two targets. Just do:

grunt.registerTask('basic', ['concat:one', 'concat:two']);

Otherwise if you're intending on concatenating the files from one and two all together do:

grunt.initConfig({
  concat: {
    one: {
      src: ['src/**/*.js'],
      dest: 'dist/<%= pkg.name %>_ac.js'
    },
    two: {
      src: ['/types/**/*.js'],
      dest: 'dist/<%= pkg.name %>_lib.js'
    },
    all: {
      src: ['<%= concat.one.src %>', '<%= concat.two.src %>'],
      dest: 'dist/<%= pkg.name %>_all.js'
    }
  }
});

Upvotes: 5

Related Questions