共计 675 个字符,预计需要花费 2 分钟才能阅读完成。
‘use strict’
var gulp = require(‘gulp’);
var watch = require(‘gulp-watch’);
var babel = require(‘gulp-babel’);
let sourcemaps = require(‘gulp-sourcemaps’);
let uglify = require(‘gulp-uglify’);
gulp.task(‘transform’, () => {
return gulp.src(‘server/**/*.js’) // 匹配 server 文件夹下面的所有 js 文件
.pipe(sourcemaps.init()) //
.pipe(babel())
.pipe(sourcemaps.write(‘.’))
.pipe(gulp.dest(‘dist/server’)); // 写入 ‘dist/server/’ 文件夹下
});
gulp.task(‘watch’, () => {
return gulp.src(‘server/**/*.js’)
.pipe(watch(‘server/**/*.js’, {
verbose: true
}))
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(uglify({ mangle: false}))
.pipe(sourcemaps.write(‘.’))
.pipe(gulp.dest(‘dist/server/’));
});
// 执行 transform 任务
gulp.task(‘default’, () => {
gulp.start(‘transform’);
});