bruh
bruh

Reputation: 2305

Grunt custom targets

Let's say I have 3 target modes for grunt: quick, build and dist

I also have a custom target make-stuff:

grunt.registerTask('make-stuff', [
            'someCSStask',
            'someUtility',
            'somePackage',
            'isolatedTask' // More on this below
        ]);

...that runs in all 3 of the above target modes (quick, build, dist) like so:

grunt.registerTask('quick', [
        'some-task1',
        'make-stuff'
    ]);

grunt.registerTask('build', [
        'some-task1',
        'some-task2',
        'make-stuff'
    ]);

grunt.registerTask('dist', [
        'some-task3',
        'build' // make-stuff gets ran here since we reference 'build'
    ]);

I would like to run make-stuff normally in each target mode, except quick, where I want it to ignore isolatedTask

Upvotes: 0

Views: 61

Answers (1)

abeach3
abeach3

Reputation: 36

If this is your setup, why not move 'isolatedTask' into build?

grunt.registerTask('build', [
    'some-task1',
    'some-task2',
    'make-stuff',
    'isolatedTask'
]);

Otherwise, try something like this

grunt.registerTask(
   'isolatedTask',
   'Isolated tasks for make-stuff, skip if target mode is quick.',
   function() {
      var target = this.args[0];
      if (target === 'quick') { return; }

      // logic here
   }
);

grunt.registerTask(
   'quick', 
   function() {
      grunt.run.tasks([
          ...,
          'isolatedTask:' + this.nameArgs
      ]);
   }
);

Upvotes: 1

Related Questions