javascript gulpfile配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 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);

以上是关于javascript gulpfile配置的主要内容,如果未能解决你的问题,请参考以下文章

gulp运行及gulpfile.js配置

javascript Django的Gulpfile

javascript Gulpfile.js(第4版)

javascript Gulpfile Compact

javascript Gulpfile 2019

javascript Gulp 4示例gulpfile.js