grunt——合并压缩css和js

npm文档:www.npmjs.com

[GruntFile.js]

module.exports = function(grunt) {
    grunt.initConfig({
        timestamp:‘<%= grunt.template.today("yyyymmddHHMM") %>‘,
        jspath:‘app/js/‘,
        csspath:‘app/css/‘,
        concat: {
            js:{
                options: {
                    separator: ‘;‘
                },
                src: [
                    "<%= jspath %>template.js",
                    "<%= jspath %>returnCode.js",
                ],
                dest: ‘<%= jspath %>all.<%= timestamp %>.js‘          
            },
            css:{
                src: [
                    ‘<%= csspath %>manage.css‘,
                    ‘<%= csspath %>jqpagination.css‘
                ],
                dest: ‘<%= csspath %>all.<%= timestamp %>.css‘
            }
        },
        uglify: {
            options: {
                banner: ‘/*! <%= concat.js.dest %> */\n‘
            },
            dist: {
                files: {
                    ‘<%= jspath %>all.min.<%= timestamp %>.js‘: [‘<%= concat.js.dest %>‘]
                }
            }
        },
        cssmin: {
            minify: {
                expand: true,
                cwd: ‘<%= csspath %>‘,
                src: ‘all.<%= timestamp %>.css‘,
                dest: ‘<%= csspath %>‘,
                ext: ‘.min.<%= timestamp %>.css‘
            }
        }
    });
    grunt.loadNpmTasks(‘grunt-contrib-concat‘);
    grunt.loadNpmTasks(‘grunt-contrib-uglify‘);
    grunt.loadNpmTasks(‘grunt-contrib-cssmin‘);
    grunt.registerTask(‘default‘, [‘concat‘,‘uglify‘,‘cssmin‘]);

};

 

[pakeage.json]

{
  "name": "test",
  "author": "youryida",  
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-concat": "^0.4.0",
    "grunt-contrib-uglify": "^0.4.0",
    "grunt-contrib-cssmin": "latest"
  }
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。