[JavaScript] 纯文本查看 复制代码
var gulp = require('gulp');
var ejs = require('gulp-ejs')
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
gulp.task('default', ['serve']);
//监听任务,监听如果有文件变动,触发reload任务
gulp.task("watch", function() {
return gulp.watch(["./src/**/*.*"], ["reload"]);
});
//reload任务,执行之前调用html任务
gulp.task("reload", ['ejs'], function(cb) {
return browserSync.reload();
});
//开启服务器任务,调用ejs和监听任务
gulp.task('serve', ['ejs', 'watch'], function() {
browserSync.init({
files: "./**/*",
server: "./dist"
});
});
gulp.task('ejs', ["style", 'js'], function() {
return gulp.src("./src/*.ejs")
.pipe(ejs({ msg: 'Hello Gulp!' }, {}, { ext: '.html' }))
.pipe(gulp.dest("./dist"))
})
gulp.task('style',['sass'], function() {
return gulp.src('./src/**/*.css')
.pipe(gulp.dest("./dist"))
})
gulp.task('js', function() {
return gulp.src('./src/**/*.js')
.pipe(uglify({ mangle: { toplevel: true } }))
.pipe(gulp.dest('./dist'))
})
gulp.task('sass', function() {
return gulp.src('./src/**/*.scss')
.pipe(sass())
.pipe(gulp.dest('./dist'))
})