vue webpack压缩代码_vue.js - 解决vue-cli打包后自动压缩代码

当我们用vue脚手架做完项目后,npm run build打包之后,

有没有查看源码,全是压缩好的。但是我就不想让它压缩,该怎么办呢?

困惑了几天,查了各种资料。终于终于...

来,上干货:

首先,我们得了解一点点webpack的知识。

webpack中压缩js 的插件叫 uglifyjs-webpack-plugin,

压缩css 的插件叫 optimize-css-assets-webpack-plugin

然后我们找到/build/webpack.prod.conf.js 文件,

然后你会发现:

const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')

const UglifyJsPlugin= require('uglifyjs-webpack-plugin')

然后我们就可以在页面中搜索OptimizeCSSPlugin 和 UglifyJsPlugin 这两个关键词所在的地方

配置如下:

//css 压缩代码,将下面代码注释掉

newOptimizeCSSPlugin({

cssProcessorOptions: config.build.productionSourceMap? { safe: true, map: { inline: false} }

: { safe:true}

}),

//压缩js代码,将下面代码注释掉

newUglifyJsPlugin({

uglifyOptions: {

compress: {

warnings:false}

},

sourceMap: config.build.productionSourceMap,

parallel:true}),

只要将上面代码注释掉,npm run build 你就会发现,欧了。

然后是html 了,

配置如下:

newHtmlWebpackPlugin({

filename: process.env.NODE_ENV=== 'testing'

? 'index.html': config.build.index,

template:'index.html',

inject:true,

minify: {

removeComments:true,

collapseWhitespace:true,

removeAttributeQuotes:true

//more options:

//https://github.com/kangax/html-minifier#options-quick-reference

},

这里我们将上面的 minify 改成 minify:false

是的,就可以了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
index.js:4130 Cannot find module './uni_modules/uview-ui/components/u-navbar/u-navbar.vue' Qld0 @ index.js:4130 __webpack_require__ @ index.js:854 fn @ index.js:151 JLrY @ index.js:1430 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ kyBj:2 kyBj @ index.js:4897 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ main.js:36 Tglg @ index.js:4322 __webpack_require__ @ index.js:854 fn @ index.js:151 1 @ index.js:1057 __webpack_require__ @ index.js:854 checkDeferredModules @ index.js:46 (anonymous) @ index.js:994 (anonymous) @ index.js:997 index.js:4131 1. 排查组件名称拼写是否正确 Qld0 @ index.js:4131 __webpack_require__ @ index.js:854 fn @ index.js:151 JLrY @ index.js:1430 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ kyBj:2 kyBj @ index.js:4897 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ main.js:36 Tglg @ index.js:4322 __webpack_require__ @ index.js:854 fn @ index.js:151 1 @ index.js:1057 __webpack_require__ @ index.js:854 checkDeferredModules @ index.js:46 (anonymous) @ index.js:994 (anonymous) @ index.js:997 index.js:4132 2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom Qld0 @ index.js:4132 __webpack_require__ @ index.js:854 fn @ index.js:151 JLrY @ index.js:1430 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ kyBj:2 kyBj @ index.js:4897 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ main.js:36 Tglg @ index.js:4322 __webpack_require__ @ index.js:854 fn @ index.js:151 1 @ index.js:1057 __webpack_require__ @ index.js:854 checkDeferredModules @ index.js:46 (anonymous) @ index.js:994 (anonymous) @ index.js:997 index.js:4135 3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件 Qld0 @ index.js:4135 __webpack_require__ @ index.js:854 fn @ index.js:151 JLrY @ index.js:1430 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ kyBj:2 kyBj @ index.js:4897 __webpack_require__ @ index.js:854 fn @ index.js:151 eval @ main.js:36 Tglg @ index.js:4322 __webpack_require__ @ index.js:854 fn @ index.js:151 1 @ index.js:1057 __webpack_require__ @ index.js:854 checkDeferredModules @ index.js:46 (anonymous) @ index.js:994 (anonymous) @ index.js:997 Request.js:53 Uncaught TypeError: f is not a function at Request.setConfig (Request.js:53:23) at Object.install (http.interceptor.js:4:24) at Vue.use (chunk-vendors.js:7461:22) at eval (main.js:160:5) at Object.Tglg (index.js:4322:1) at __webpack_require__ (index.js:854:30) at fn (index.js:151:20) at 1 (index.js:1057:18) at __webpack_require__ (index.js:854:30) at checkDeferredModules (index.js:46:23)解决
最新发布
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值