我正在尝试在 grunt 中创建一个自动调用其“先决条件”的自定义任务。我不确定该怎么做。 Grunt.js docs显示这个例子:
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
和 baz
排入队列”,我想在那里执行它们,其中 grunt.task.run
行是,所以它们在我的“其他东西”之前被执行。
我该怎么做?
最佳答案
我认为您目前唯一的方法是通过创建和附加任务
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']);
关于javascript - 如何在我的任务代码运行之前*从我的自定义任务中调用其他任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15100565/