Pass params to an grunt task from an alias task

2020-07-05 08:43发布

Is there a way to pass an argument from a alias task like this into on of the calling tasks:

grunt.registerTask('taskA', ['taskB', 'taskC'])

grunt taskA:test

so that task taskB and taskC will be called with the parameter test?

标签: gruntjs
1条回答
老娘就宠你
2楼-- · 2020-07-05 09:22

You can create a dynamic alias task like this:

grunt.registerTask('taskA', function(target) {
  var tasks = ['taskB', 'taskC'];
  if (target == null) {
    grunt.warn('taskA target must be specified, like taskA:001.');
  }
  grunt.task.run.apply(grunt.task, tasks.map(function(task) {
    return task + ':' + target;
  }));
});

Here is the FAQ with another example in the Grunt docs: http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

查看更多
登录 后发表回答