JS: gulp.js

var gulp = require('gulp'),

minify = require('gulp-minify-css'),//css压缩

uglify = require('gulp-uglify'),//js压缩

htmlmin = require('gulp-htmlmin');

gulp.task('minhh', function () {

var options = {

removeComments: true,//清除HTML注释

collapseWhitespace: true,//压缩HTML

collapseBooleanAttributes: true,//省略布尔属性的值 ==>

removeEmptyAttributes: true,//删除所有空格作属性值 ==>

removeScriptTypeAttributes: true,//删除的type="text/javascript"

removeStyleLinkTypeAttributes: true,//删除和的type="text/css"

minifyJS: true,//压缩页面JS

minifyCSS: true//压缩页面CSS

};

gulp.src('src/www/pages/*/*.html')

.pipe(htmlmin(options))

.pipe(gulp.dest('dist/www/pages'));

});

gulp.task('minHtml', function () {

var options = {

removeComments: true,//清除HTML注释

collapseWhitespace: true,//压缩HTML

//collapseBooleanAttributes: true,//省略布尔属性的值 ==>

//removeEmptyAttributes: true,//删除所有空格作属性值 ==>

//removeScriptTypeAttributes: true,//删除的type="text/javascript"

// removeStyleLinkTypeAttributes: true,//删除和的type="text/css"

minifyJS: true,//压缩页面JS

minifyCSS: true//压缩页面CSS

};

gulp.src('src/www/html/*/*.html')

.pipe(htmlmin(options))

.pipe(gulp.dest('dist/www/html'));

});

gulp.task('mincss',function(){

gulp.src('src/www/css/*.css')

.pipe(minify())

.pipe(gulp.dest('dist/www/css'));

});

gulp.task('minjs',function(){

gulp.src('src/www/js/*.js')

.pipe(uglify())

.pipe(gulp.dest('dist/www/js'));

});

推荐阅读更多精彩内容