首页 > 代码库 > gulp——myself配置

gulp——myself配置

var gulp = require(‘gulp‘),
    uglify = require(‘gulp-uglify‘),
    concat = require(‘gulp-concat‘);
 var pump = require(‘pump‘);
 var minifycss = require(‘gulp-minify-css‘);
 var htmlmin = require(‘gulp-htmlmin‘);
gulp.task(‘compress‘, function (cb) {
    pump([
            gulp.src(‘app/**/*.js‘),
            uglify(),

            gulp.dest(‘build‘)
        ],
        cb
    );
});


gulp.task(‘default‘, function () {
    gulp
        .src(‘app/**/*.js‘) // gulp.src从水源地把水取出来,创造第一根管子
        //.pipe(concat(‘all.js‘))
        .pipe(uglify()) // 新建一个管子,然后把水处理器塞到管子里面
        // gulp.dest(‘build‘) 其实也是一种水处理器,它的作用是把水引流到某个文件夹下面
        .pipe(gulp.dest(‘dist/js‘))
});
/*var htmlmin = require(‘gulp-htmlmin‘);
 gulp.task(‘html‘, function () {
 var options = {
 collapseWhitespace: true,
 collapseBooleanAttributes: true,
 removeComments: true,
 removeEmptyAttributes: true,
 removeScriptTypeAttributes: true,
 removeStyleLinkTypeAttributes: true,
 minifyJS: true, minifyCSS: true
 };
 gulp.src(‘app/*.html‘)
 .pipe(htmlmin(options))
 //.pipe(rename({suffix: ‘.min‘}))
 //.pipe(concat(‘index.html‘))
 .pipe(gulp.dest(‘/dist/html‘));
 });
 */


gulp.task(‘htmlmin‘, function() {
    return gulp.src([‘app/*/*.html‘, ‘app/*.html‘])
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(‘dist/html‘))
        //.pipe($.notify({ message: ‘htmlmin task done‘ }));
});

////压缩css
gulp.task(‘css‘, function () {
    gulp.src(‘app/css/*.css‘)      //压缩的文件
        //.pipe(rename({suffix: ‘.min‘}))
        .pipe(minifycss()) //执行压缩
        .pipe(concat(‘index.css‘))
        .pipe(gulp.dest(‘./dist/css‘))   //输出文件夹
});

gulp.task(‘watch‘,function(){
    var watcher = gulp.watch(‘app/*.js‘,[‘default‘])

});

 

gulp——myself配置