打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Gulp自动化构建案例---文件压缩

1、安装压缩插件

yarn add gulp-htmlmin gulp-uglify gulp-clean-css --dev

2、安装判断读取流类型的插件

yarn add gulp-if --dev

3、使用

const useref = () => {
  return src('dist/*.html',{base:'dist'})
  .pipe(plugins.useref({searchPath:['dist','.']}))
  //html js css
  //指定转换流
  //压缩空白字符collapseWhitespace
  //minifyCSS:true,minifyJS:true,压缩html页面中的css和js
  .pipe(plugins.if(/\.js$/,plugins.uglify()))
  .pipe(plugins.if(/\.css$/,plugins.cleanCss()))
  .pipe(plugins.if(/\.html$/,plugins.htmlmin({
    collapseWhitespace:true,
    minifyCSS:true,
    minifyJS:true
  })))
  .pipe(dest('release'))
}

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Gulp自动化构建案例---重新规划构建过程
Gulp
gulp基础教程 | Reeoo's Blog
gulp+webpack构建配置
入门:十分钟自动化构建
Gulp自动添加版本号
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服