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

我正在尝试在grunt中创build一个自动调用其“先决条件”的自定义任务。 我不确定如何做到这一点。 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 }); 

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

我怎么做?

我认为你现在唯一的方法是通过创build和额外的任务

 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']);