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

前端 未结 5 415
半阙折子戏
半阙折子戏 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 18:48

    You don't need to add the concat package, you can do this via cssmin like this:

    cssmin : {
          options: {
                keepSpecialComments: 0
          },
          minify : {
                expand : true,
                cwd : '/library/css',
                src : ['*.css', '!*.min.css'],
                dest : '/library/css',
                ext : '.min.css'
          },
          combine : {
            files: {
                '/library/css/app.combined.min.css': ['/library/css/main.min.css', '/library/css/font-awesome.min.css']
            }
          }
        }
    

    And for js, use uglify like this:

    uglify: {
          my_target: {
            files: {
                '/library/js/app.combined.min.js' : ['/app.js', '/controllers/*.js']
            }
          }
        }
    

提交回复
热议问题