Pass params to an grunt task from an alias task

半腔热情 提交于 2019-12-21 08:07:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/16239254/pass-params-to-an-grunt-task-from-an-alias-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!