gulp 命令行接受参数

2017-03-01  本文已影响403人  开车去环游世界
"use strict";

import gulp from "gulp";
import gulpif from "gulp-if";
import uglify from "gulp-uglify";
import minimist from "minimist";

const dirs = {
    src: "src/js",
    dist: "dist/js"
};

const paths = {
    src: `${dirs.src}/*.js`,
    dist: `${dirs.dist}`
};

let knownOptions = {
  string: "env",
  default: {
      key: true,
      env: process.env.NODE_ENV || "production"
   }
};

let options = minimist( process.argv.slice(2), knownOptions );

// eg: gulp game --env production --key dts
gulp.task("game", () => {
    console.log( options.key, options.env );
    return gulp.src(paths.src)
    .pipe(gulpif(options.env === "production", uglify())) // 仅在生产环境时(正式环境)候进行压缩
    .pipe(gulp.dest(paths.dist));
});

上一篇下一篇

猜你喜欢

热点阅读