gulp 命令行接受参数

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

你可能感兴趣的:(gulp 命令行接受参数)