gulpfile.js备份

var gulp = require('gulp');

var uglify = require('gulp-uglify');

// var rename = require('gulp-rename');
// var imagemin = require("gulp-imagemin");
// var pngquant = require('imagemin-pngquant');
// //确保本地已安装gulp-cache [cnpm install gulp-cache --save-dev]
// var cache = require('gulp-cache');

var less = require('gulp-less');

var htmlmin = require('gulp-htmlmin');

var minicss = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');




gulp.task('less', function() {
    gulp.src('css/*.less')
        .pipe(less())
        .pipe(autoprefixer({
            browsers: ['last 2 versions', 'Android >= 4.0'],
            cascade: true, //是否美化属性值 默认:true 像这样:
            //-webkit-transform: rotate(45deg);
            //        transform: rotate(45deg);
            remove:true //是否去掉不必要的前缀 默认:true
        }))
        .pipe(minicss())
        .pipe(gulp.dest('dist/css'));
})

gulp.task('img',function(){
    gulp.src('img/*{png,svg,ico,jpg,gif}')
        .pipe(gulp.dist('dist/img'))
})
gulp.task('html', function() {
    var options = {
        removeComments: true, //清除HTML注释
        collapseWhitespace: true, //压缩HTML
        collapseBooleanAttributes: true, //省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: true, //删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true, //删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type="text/css"
        minifyJS: true, //压缩页面JS
        minifyCSS: true //压缩页面CSS
    };
    gulp.src('*.html')
        .pipe(htmlmin(options))
        .pipe(gulp.dest('dist'));
})


gulp.task('js', function() {
    gulp.src('js/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'));
})


gulp.task('auto', function() {
    gulp.watch('*.html', ['html']);
    gulp.watch('js/*.js', ['js']);
    gulp.watch('css/*.less', ['less']);
    gulp.watch('img/*.{svg,mpng,jpg,gif,ico}',['img']);
})

gulp.task('default', ['auto']);

css: less编译css ,自动添加前缀,压缩。 html : 压缩 。 js:压缩

posted @ 2017-03-02 16:09  无情码字员  阅读(269)  评论(0编辑  收藏  举报