I'm trying to create a custom task in grunt that automatically invokes its "prerequisites". I'm not sure on how to do that. The Grunt.js docs show this example:
我正在尝试在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
});
I don't want to "enqueue bar
and baz
after foo
", I want to execute them right there, where the grunt.task.run
line is, so they get executed before my "Other stuff".
我不想“在foo之后将bar和baz排队”,我想在那里执行它们,grunt.task.run行在那里,所以它们在我的“其他东西”之前执行。
How do I do that?
我怎么做?
1 个解决方案
#1
12
I think your only way to do it currently would be via creating and additional task
我认为你目前唯一的做法是通过创建和额外的任务
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']);
#1
12
I think your only way to do it currently would be via creating and additional task
我认为你目前唯一的做法是通过创建和额外的任务
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']);