less js img html /** * Created by gaoshan on 2017/9/21 0021. *//* * 1. less 编译 压缩 合并 * 2. js 合并 压缩 混淆 * 3. img 复制 * 4. html 压缩 */var gulp = require('gulp');var less = require('gulp-less');var concat = require
/** * Created by gaoshan on 2017/9/21 0021. */ /* * 1. less 编译 压缩 合并 * 2. js 合并 压缩 混淆 * 3. img 复制 * 4. html 压缩 */ var gulp = require('gulp'); var less = require('gulp-less'); var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); var htmlmin = require('gulp-htmlmin'); var browserSync = require('browser-sync'); gulp.task('style', function () { gulp.src('src/css/*.less') .pipe(less()) .pipe(gulp.dest('dist/css')) .pipe(browserSync.reload({ stream: true })); }); gulp.task('script', function () { gulp.src('src/js/*.js') .pipe(concat('main.js')) .pipe(uglify()) .pipe(gulp.dest('dist/js')) .pipe(browserSync.reload({ stream: true })); }); gulp.task('image', function () { gulp.src('src/img/*') .pipe(gulp.dest('dist/img')) .pipe(browserSync.reload({ stream: true })); }); gulp.task('html', function () { gulp.src('src/*.html') .pipe(htmlmin({ collapseWhitespace: true })) .pipe(gulp.dest('dist/')) .pipe(browserSync.reload({ stream: true })); }); gulp.task('serve', function () { browserSync({ server: { baseDir: ['dist'] } }, function (err, bs) { }); gulp.watch('src/css/*.less', ['style']); gulp.watch('src/js/*.js', ['script']); gulp.watch('src/img/*', ['image']); gulp.watch('src/*.html', ['html']); });