gulp打包

gulp打包主要注重工作流程的构建。

一般先在package.json中添加需要的gulp插件,通过npm或者yarn安装,然后在gulpfile.js中写构建脚本.

主要用到的插件有:

gulp-usemin: 根据html页面创建压缩html,css,js...的构建任务;

gulp-htmlmin: 压缩html

gulp-clean-css: 压缩css

gulp-uglity: 压缩js

gulp-concat: 合并文件

gulp-template-compile: 转换html模板为js

gulp-exec:  执行cmd 命令

del : 删除文件(夹)

webpack-stream: 执行webpack打包

实例:

const gulp = require("gulp");const del = require("del");

const exec = require('child_process').exec;
const uglify = require("gulp-uglify");
const cleanCSS = require("gulp-clean-css");
const concat = require("gulp-concat");
const template = require("gulp-template-compile");
const base64 = require("gulp-base64");
const webpack = require("webpack-stream");
 
let outPath = "./dist"; // 压缩后文件的放置位置
// gulp.task("任务名", 任务体): 创建任务
gulp.task("cleanDir", () => {
   return del(outPath, { force: true}); 
}
// copy 文件---一般将一些不必压缩的mock数据、图片等直接拷贝过去
gulp.task("copyResource", () => {
return gulp.src("源文件路径")
      .pipe(gulp.dest("目标路径"));
});
原文地址:https://www.cnblogs.com/qingxiawu/p/8782629.html