将params传递给别名任务中的咕噜任务 [英] Pass params to an grunt task from an alias task

查看:130
本文介绍了将params传递给别名任务中的咕噜任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将这样一个别名任务的参数传递给调用任务:

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

,因此任务 taskB taskC 将被调用参数 test

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

推荐答案

您可以像这样创建动态别名任务:

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;
  }));
});

以下是Grunt文档中另一个示例的FAQ: http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

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

这篇关于将params传递给别名任务中的咕噜任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆