首页 > 代码库 > grunt——合并压缩css和js

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"  }}

 

grunt——合并压缩css和js