问题 在我的任务代码运行之前,如何从我的自定义任务*调用其他任务?


我正在尝试在grunt中创建一个自动调用其“先决条件”的自定义任务。我不知道该怎么做。该 Grunt.js文档 显示这个例子:

grunt.registerTask('foo', 'My "foo" task.', function() {
  // Enqueue "bar" and "baz" tasks, to run after "foo" finishes, in-order.
  grunt.task.run('bar', 'baz');
  ... // Other stuff here
});

我不想“入队” bar 和 baz 后 foo“,我想在那里执行它们,在那里 grunt.task.run 是的,所以他们在我的“其他东西”之前被执行。

我怎么做?


13065
2018-02-26 22:23


起源



答案:


我认为你目前唯一的做法是通过创建和额外的任务

grunt.registerTask('fooTask', 'My "foo" task.', function() {
  grunt.task.requires('bar'); // make sure bar was run and did not fail
  grunt.task.requires('baz'); // make sure bar was run and did not fail
  ... // Other stuff here
});

grunt.registerTask('foo', 'My "foo" sequence.', ['bar', 'baz', 'fooTask']);

12
2018-02-26 22:54



嗯,这有点令人失望。至少我不会浪费更多时间寻找解决方案。谢谢! - kikito


答案:


我认为你目前唯一的做法是通过创建和额外的任务

grunt.registerTask('fooTask', 'My "foo" task.', function() {
  grunt.task.requires('bar'); // make sure bar was run and did not fail
  grunt.task.requires('baz'); // make sure bar was run and did not fail
  ... // Other stuff here
});

grunt.registerTask('foo', 'My "foo" sequence.', ['bar', 'baz', 'fooTask']);

12
2018-02-26 22:54



嗯,这有点令人失望。至少我不会浪费更多时间寻找解决方案。谢谢! - kikito