Pass params to an grunt task from an alias task

后端 未结 1 943
悲&欢浪女
悲&欢浪女 2021-02-20 11:35

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:t         


        
相关标签:
1条回答
  • 2021-02-20 12:33

    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

    0 讨论(0)
提交回复
热议问题