grunt
// npm install -g grunt-cli
// npm install grunt –save-dev
// npm install grunt-contrib-csslint –save-dev
// npm install grunt-contrib-less –save-dev
// npm install grunt-contrib-cssmin –save-dev
// npm install grunt-contrib-concat –save-dev
// npm install grunt-contrib-jshint –save-dev
// npm install grunt-contrib-uglify –save-dev
// npm install grunt-contrib-watch –save-dev
// Gruntfile.js 1
module.exports = function(grunt){
//初始化grunt 配置
grunt.initConfig({
//获取package.json的信息
pkg: grunt.file.readJSON('package.json'),
//concat插件的配置信息
concat: {
options:{
stripBanners:true, //合并时允许输出头部信息
banner:'/\*!<%= pkg.name %> - <%= pkg.version %>-'+'<%=grunt.template.today("yyyy-mm-dd") %> \*/'
},
cssConcat:{
src:\['src/css/css1.css','src/css/css2.css'\],
dest:'src/css/concat/<%= pkg.name %> - <%= pkg.version %>.css' //dest 是目的地输出
},
jsConcat:{
src:'src/js/\*.js',
dest:'src/js/concat/<%=pkg.name %> - <%= pkg.version %>.js'
}
},
//压缩css
cssmin:{
options:{
stripBanners:true, //合并时允许输出头部信息
banner:'/\*!<%= pkg.name %> - <%= pkg.version %>-'+'<%=grunt.template.today("yyyy-mm-dd") %> \*/\\n'
},
build:{
src:'src/css/concat/<%=pkg.name %> - <%=pkg.version %>.css',//压缩是要压缩合并了的
dest:'dist/css/<%= pkg.name %> - <%= pkg.version %>.min.css' //dest 是目的地输出
}
},
//压缩js
uglify:{
options:{
stripBanners:true, //合并时允许输出头部信息
banner:'/\*!<%= pkg.name %> - <%= pkg.version %>-'+'<%=grunt.template.today("yyyy-mm-dd") %> \*/\\n'
},
build:{
src:'src/js/concat/<%=pkg.name %> - <%=pkg.version %>.js',//压缩是要压缩合并了的
dest:'dist/js/<%= pkg.name %> - <%= pkg.version %>.min.js' //dest 是目的地输出
}
},
jshint:{
options:{
jshintrc:'.jshint'
},
build:\['Gruntfile.js','src/js/\*js'\]
},
csslint:{
options:{
csslintrc:'.csslint'
},
build:\['src/css/\*.css'\]
},
//watch自动化
watch:{
build:{
files:\['src/js/\*.js','src/css/\*.css'\],
tasks:\['jshint','csslint','concat','cssmin','uglify'\],
options:{spawn:false}
}
}
});
//告诉grunt我们将使用插件
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-contrib-watch');
//告诉grunt当我们在终端输入grunt时需要做些什么
grunt.registerInitTask('default',\['jshint','csslint','concat','cssmin','uglify','watch'\]);//先进行语法检查,如果没有问题,再合并,再压缩
};
// Gruntfile.js 1
module.exports = function (grunt) {
‘use strict’;
grunt.initConfig({
pkg: grunt.file.readJSON(‘package.json’),
less: {
development: {
options: {
paths: [“./“]
},
files: [{
expand: true,
cwd: ‘./public/dev/less’,
src: [‘**/g.less’],
dest: ‘public/dev/less’,
ext: ‘.css’
}]
}
},
cssmin: {
target: {
files: [{
expand: true,
cwd: ‘./public/dev/less’,
src: [‘*.css’, ‘!*.min.css’],
dest: ‘public/css’,
ext: ‘.min.css’
}]
}
},
concat: {
options: {
stripBanners: true,
banner: ‘/* <%=pkg.name%>-<%=pkg.verson%>.js <%=grunt.template.today(“yyyy-mm-dd”)%> */‘
},
es6: {
src:[
‘/libs/es5-shim/4.5.7/es5-shim.min.js’,
‘/libs/es5-shim/4.5.7/es5-sham.min.js’,
‘/libs/json3/3.3.2/json3.min.js’,
‘/libs/es6-shim/0.34.2/es6-shim.min.js’,
‘/libs/es6-shim/0.34.2/es6-sham.min.js’,
‘/libs/axios/0.16.0/axios.min.js’
],
dest:’./public/dev/js/es5~es6.js’
},
plugins: {
src: [‘b.js’, ‘c.js’],
dest: ‘all-sec.js’,
}
},
uglify: {
options: {
stripBanners: true,
banner: ‘/* <%=pkg.name%> <%=grunt.template.today(“yyyy-mm-dd”)%> by Yitong.com */‘
},
buildall: {
options:{
mangle:false,
preserveComments: ‘some’,
footer:’’
},
files: [{
expand: true,
src: ‘usercenter/*.js’,
ext:’.js’,
dest: ‘dev/js’
}]
},
build: {
files: {
‘./public/dev/js/cc.js’: [‘/libs/axios/0.16.0/axios.min.js’]
}
}
},
jshint: {
build: [‘Gruntfils.js’, ‘./public/js/usercenter/*.js’],
options: {
jshintrc: ‘.jshintrc’
}
},
watch: {
options: {
livereload: true,
spawn: false
},
build: {
files: [‘./public/dev/less/*.less’],
tasks: [‘less’,’cssmin’]
}
},
});
grunt.loadNpmTasks(‘grunt-contrib-less’);
grunt.loadNpmTasks(‘grunt-contrib-cssmin’);
grunt.loadNpmTasks(‘grunt-contrib-concat’);
grunt.loadNpmTasks(‘grunt-contrib-uglify’);
grunt.loadNpmTasks(‘grunt-contrib-jshint’);
grunt.loadNpmTasks(‘grunt-contrib-watch’);
grunt.registerTask(‘default’, [‘less’, ‘concat’, ‘uglify’,’watch’]);
};
// 启动
// grunt