UNPKG

horse-generator

Version:
130 lines (118 loc) 3.53 kB
'use strict'; var config = require('./config'); var path = require('path'); var gulp = require('gulp'), nodemon = require('gulp-nodemon'), babel = require('gulp-babel'), // uglify = require('gulp-uglify'), gutil = require('gulp-util'), minifyJS = require('gulp-minify'), sourcemaps = require('gulp-sourcemaps'), uglify = require('gulp-uglify-es').default, cache = require('gulp-file-cache') var rename = require('gulp-rename'); var plumber = require('gulp-plumber'); var plumberNotifier = require('gulp-plumber-notifier'); var sourcemaps = require('gulp-sourcemaps'); // gulp.task('compile', function () { // var stream = gulp.src(['./src/exp/**/*.js']) // your ES2015 code // // .pipe(cache.filter()) // remember files // // .pipe(sourcemaps.init({loadMaps: true})) // .pipe(babel({ // // presets: ['es2015'], // plugins: [ // 'transform-runtime', // 'transform-class-properties', // ], // })) // compile new ones // // .pipe(cache.cache()) // cache them // .pipe(minifyJS()) // .pipe(uglify()) // // .pipe(sourcemaps.write()) // .pipe(gulp.dest('./dist/src/exp')) // write them // return stream // important for gulp-nodemon to wait for completion // }) gulp.task('compile', function () { var stream = gulp.src(['./src/exp/**/*.js']) // .pipe(cache.filter()) // remember files // .pipe(plumberNotifier()) // .pipe(sourcemaps.init()) .pipe(babel({ presets: ['es2015'], plugins: [ 'transform-runtime', 'transform-class-properties', ], })) // compile new ones // .pipe(cache.cache()) // cache them .pipe(minifyJS({ fromString: true, mangle: true, })) .pipe(uglify()) // .pipe(cache.cache()) // cache them // .pipe(rename(function (path) { // path.extname = '.min.js'; // })) // .pipe(sourcemaps.write('.')) .pipe(gulp.dest('./dist/src/exp')) // write them return stream // important for gulp-nodemon to wait for completion }) gulp.task('copyBin', function () { return gulp.src( ['./bin/www'], // {cwdbase: true}, ) // .pipe(minifyJS()) .pipe(uglify()) .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); }) .pipe(gulp.dest('./dist/bin')); }) gulp.task('watch', ['copyBin', 'compile'], function () { var stream = nodemon({ // script: 'dist/server', // run ES5 code script: 'dist/bin/www', // run ES5 code watch: 'src/exp', // watch ES2015 code tasks: ['compile'], // compile synchronously onChange // ext: 'js html', // ignore: ['ignored.js'], }) return stream }) // 默认development模式 gulp.task('nodemon', function () { nodemon({ // script: path.join(config.paths.server, '/app.js'), script: config.paths.server, ext: 'js', watch: [ path.join(config.paths.server, '/'), ], }) }); // test模式 gulp.task('nodemon:test', function () { nodemon({ script: config.paths.server, ext: 'js json', watch: [ path.join(config.paths.server, '/'), ], env: { 'NODE_ENV': 'test' }, }) }); // production模式 gulp.task('nodemon:pro', function () { nodemon({ script: config.paths.server, ext: 'js json', watch: [ path.join(config.paths.server, '/'), ], env: { 'NODE_ENV': 'production' }, }) }); gulp.task('serve', ['watch']); // gulp.task('serve', ['nodemon']); gulp.task('serve:test', ['nodemon:test']); gulp.task('serve:pro', ['nodemon:pro']);