How to concatenate and minify multiple CSS and JavaScript files with Grunt.js (0.3.x)

前端 未结 5 431
半阙折子戏
半阙折子戏 2020-11-28 18:18

Note: This question is only relevant for Grunt 0.3.x and has been left for reference. For help with the latest Grunt 1.x release please see my comment below this questio

5条回答
  •  盖世英雄少女心
    2020-11-28 19:05

    I agree with above answer. But here is another way of CSS compression.

    You can concat your CSS by using YUI compressor:

    module.exports = function(grunt) {
      var exec = require('child_process').exec;
       grunt.registerTask('cssmin', function() {
        var cmd = 'java -jar -Xss2048k '
          + __dirname + '/../yuicompressor-2.4.7.jar --type css '
          + grunt.template.process('/css/style.css') + ' -o '
          + grunt.template.process('/css/style.min.css')
        exec(cmd, function(err, stdout, stderr) {
          if(err) throw err;
        });
      });
    }; 
    

提交回复
热议问题