Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance(fix):新增生产模式代码压缩,减小dist包体积 #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
Expand Down
26 changes: 24 additions & 2 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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;
Expand Down