x1nfly
5/14/2019 - 1:48 AM

gulpfile 配置

// 1. 先安装相应插件:

/*
npm install --save-dev gulp
npm install --save-dev gulp-clean-css
npm install --save gulp-rename
npm install --save readable-stream
npm install --save-dev gulp-uglify
*/

// 2. 项目根目录下创建 gulpfile.js 文件

let gulp = require('gulp');
let uglify = require('gulp-uglify');
let rename = require('gulp-rename');
let cleanCSS = require('gulp-clean-css');
let pipeline = require('readable-stream').pipeline;

function compressJS () {
  return pipeline(
    gulp.src('path/to/xx.js'),
    uglify(),
    rename({
      suffix: '.min'
    }),
    gulp.dest('dist')
  );
}

function compressCSS () {
  return pipeline(
    gulp.src(['path/to/xx1.css', 'path/to/xx2.css']),
    cleanCSS(),
    rename({
      suffix: '.min'
    }),
    gulp.dest('dist')
  );
}

exports.default = gulp.series(compressJS, compressCSS);