gulp配置文件gulpfile.babel.js

'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');
});
相關文章
相關標籤/搜索