配置css和js文件发生变化就重新合并压缩css和js文件
package.json
{
"name": "AngularAndRequire",
"version": "0.1.0",
"description" : "AngularAndRequire1.0",
"author": "Mario.Li",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-uglify": "~0.2.1",
"grunt-contrib-concat": "~0.1.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-css": "~0.5.4"
}
}
Gruntfile.js
'use strict'
module.exports = function(grunt) {
// 配置
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
concat : {
libs : {
src: ['frontend/libs/*.js', '!frontend/libs/require.js'],
dest: 'dest/libs.js'
},
custs: {
src: ['frontend/**/*.js', '!frontend/libs/*.js'],
dest: 'dest/cust.js'
},
css : {
src : ['frontend/styles/*.css', '!frontend/styles/index.css'],
dest : 'dest/index.css'
}
},
uglify : {
options : {
banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
buildlibs : {
src : 'dest/libs.js',
dest : 'dest/libs.min.js'
},
buildcusts : {
src : 'dest/cust.js',
dest : 'dest/cust.min.js'
},
},
cssmin : {
buildCss : {
src : 'dest/index.css',
dest : 'dest/index.min.css'
}
},
watch : {
all : {
files :['**/*.js', '**/*.css'],
tasks : ['concat', 'uglify', 'cssmin']
}
}
});
// 载入concat和uglify插件,分别对于合并和压缩
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-css');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// 注册任务
grunt.registerTask('default', ['concat', 'uglify', 'cssmin', 'watch']);
};