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');
});

    原文作者:liuoomei
    原文地址: https://segmentfault.com/a/1190000018520071
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞