最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to call tasks from code in Grunt if helpers are gone - Stack Overflow

programmeradmin8浏览0评论

Grunt is removing the helpers and this already happened in grunt-contrib.

However I have a Grunt file relying on some custom tasks calling some of those helpers. Without helpers it breaks. I am just wondering what should be the correct way to replace those.

I get it will be by calling the tasks directly in some way but I am not sure how. An example would help a lot since Grunt documentation is not updated yet.

Thanks.

Grunt is removing the helpers and this already happened in grunt-contrib.

However I have a Grunt file relying on some custom tasks calling some of those helpers. Without helpers it breaks. I am just wondering what should be the correct way to replace those.

I get it will be by calling the tasks directly in some way but I am not sure how. An example would help a lot since Grunt documentation is not updated yet.

Thanks.

Share Improve this question asked Sep 11, 2012 at 22:25 GriffonRLGriffonRL 2,2882 gold badges18 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Ok after some research and the help of the maintainers of grunt-contrib, I rewrote that task I have:

grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() {
    grunt.file.expandFiles(this.data).forEach(function(file) {
        var minified = grunt.helper("mincss", grunt.file.read(file));
        grunt.file.write(file, minified);
        grunt.log.writeln("Minified CSS "+file);
    });
});

Into this:

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

No other change needed in the config file. The new piece of code makes use of the task itself instead of the helper that is gone.

This might not be the best approach and Grunt 0.4.0 might change the game again, but it does work right now with Grunt 0.3.15 and grunt-contrib 0.2.

发布评论

评论列表(0)

  1. 暂无评论