我如何从一个咕task任务中运行一个咕噜任务? [英] How can I run a grunt task from within a grunt task?
问题描述
我创建了一个新的grunt任务,在其中我想使用grunt-contrib-concat将几个文件连接在一起。
我浏览了文档,但没有发现任何暗示能够做到的事情。这似乎是一个微不足道的用例,所以我可能只是在看一些东西。
更新1:
我也希望能够在我的自定义任务中配置此任务。 / p>
例如,我在自定义任务中创建了一个文件列表。在获得该列表后,我想将它们传递给concat任务。我该怎么做?
我希望能够做到这样的事情。
grunt.task.run('concat',{src:['file1','file2'],dest:'out.js'})
更新2:
为了实现我想要的,我必须手动配置grunt任务。这里有一个例子显示了我想要的东西。
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
解决方案以下是在任务中手动配置任务并运行它的示例。
https://github.com / gruntjs / grunt-contrib / issues / 118#issuecomment-8482130 $ b
grunt.registerMultiTask('multicss', '在文件夹中缩小CSS文件',function(){
var count = 0;
grunt.file.expandFiles(this.data).forEach(function(file){
var property ='mincss.css'+ count +'。files';
var value = {};
value [file] = file;
grunt.config(property,value);
grunt.log.writeln(Minifying CSS+文件);
count ++;
});
grunt.task.run('mincss');
});
I've created a new grunt task and within it I want to use grunt-contrib-concat to concatenate a few files together.
I looked through the docs but I don't find anything that hinted at being able to do this. It seems like a trivial use case, so I'm probably just over looking something.
Update 1:
I also want to be able to configure this task from within my custom task.
For example, I create a list of files in my custom task. After I have that list, I want to pass them to the concat task. How can I do that?
I would like to be able to do something like this.
grunt.task.run('concat', { src: ['file1','file2'], dest: 'out.js'})
Update 2:
To achieve what I want, I have to manually configure the grunt task. Here's an example that showed me what I wanted.
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
解决方案Here's an example of manually configuring a task within a task and then running it.
https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130
grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() { var count = 0; grunt.file.expandFiles(this.data).forEach(function(file) { var property = 'mincss.css'+count+'.files'; var value = {}; value[file] = file; grunt.config(property, value); grunt.log.writeln("Minifying CSS "+file); count++; }); grunt.task.run('mincss'); });
这篇关于我如何从一个咕task任务中运行一个咕噜任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!