Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

javascript - How can I run a grunt task from within a grunt task?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...