From 307d1bb73b50d8798e316f99675dd932205e2367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=87=AA=E7=84=B6?= <15267229907@163.com> Date: Fri, 30 Jun 2023 17:26:30 +0800 Subject: [PATCH] =?UTF-8?q?performance(fix):=E6=96=B0=E5=A2=9E=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E6=A8=A1=E5=BC=8F=E4=BB=A3=E7=A0=81=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=8Fdist=E5=8C=85=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- vue.config.js | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2d86418..ea5f542 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "svg-sprite-loader": "6.0.2", "vue-i18n-locale-message": "0.16.2", "vue-jest": "3.0.7", - "vue-template-compiler": "2.6.11" + "vue-template-compiler": "2.6.11", + "uglifyjs-webpack-plugin": "2.2.0" }, "browserslist": [ "> 1%", diff --git a/vue.config.js b/vue.config.js index a67c05d..7a2319f 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,6 +1,7 @@ const path = require('path') const fs = require('fs'); const FileManagerPlugin = require('filemanager-webpack-plugin') +const UglifyJsPlugin = require('uglifyjs-webpack-plugin') function resolvePath (dir) { return path.resolve(__dirname, '.', dir) @@ -29,8 +30,29 @@ module.exports = { resolve: { alias: { 'vue$': 'vue/dist/vue.common.js' - } - } + }, + }, + plugins: isProd + ? [ + new UglifyJsPlugin({ + test: /\.js|vue(\?.*)?$/i, //包含以js、vue结尾的文件 + extractComments: false, //是否提取注释 + sourceMap: false, //是否开启sourceMap + cache: true, //是否进行压缩缓存 + parallel: true, //是否开启多线程、多核 + uglifyOptions: { + compress: { + unused: true, //去除未使用的变量和函数 + dead_code: true, //去除无用代码 + drop_debugger: true, //去除debugger语句 + drop_console: true, //去除console语句 + passes: 2, //压缩代码的次数 + sequences: true //折叠多个连续语句 + } + } + }) + ] + : [] }, chainWebpack: config => { const oneOfsMap = config.module.rule('scss').oneOfs.store;