需要用到的插件
生产时
cnpm install gulp gulp-less
发布时需要打包一次
cnpm install gulp gulp-less gulp-cssnano gulp-uglify gulp-babel babel-preset-es2015 --save-dev
'use strict';
var gulp = require('gulp');
var less = require('gulp-less');
var cssnano = require('gulp-cssnano');
var uglify = require('gulp-uglify');
var babel = require("gulp-babel");
gulp.task('style', function() {
gulp.src('src/styles/*.css')
.pipe(cssnano())
.pipe(gulp.dest('dist/styles'))
gulp.src(['src/styles/*.less', '!src/styles/_*.less'])
.pipe(less())
.pipe(cssnano())
.pipe(gulp.dest('dist/styles'))
});
gulp.task('script', function() {
gulp.src('src/scripts/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('dist/scripts'))
})
// images 图片复制
gulp.task('image', function() {
gulp.src('src/images/*.*')
.pipe(gulp.dest('dist/images'))
})
// html
gulp.task('html', function() {
gulp.src('src/*.html')
.pipe(gulp.dest('dist/'))
})
gulp.task('build', ['style', 'script','image','html'])
gulp.watch('src/styles/*.*', ['style']);
gulp.watch('src/scripts/*.js', ['script']);
gulp.watch('src/images/*.*', ['image']);
gulp.watch('src/*.html', ['html']);