Skip to content

Commit 4184e40

Browse files
committed
开启gzip压缩
1 parent 33a93a1 commit 4184e40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"babel-plugin-dynamic-import-node": "2.3.3",
5656
"chalk": "2.4.2",
5757
"chokidar": "2.1.5",
58+
"compression-webpack-plugin": "^3.1.0",
5859
"connect": "3.6.6",
5960
"eslint": "6.7.2",
6061
"eslint-plugin-vue": "6.2.2",

vue.config.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
'use strict'
22
const path = require('path')
33
const defaultSettings = require('./src/settings.js')
4-
4+
const webpackPlugins = []
5+
if (process.env.NODE_ENV === 'production') {
6+
const CompressionPlugin = require('compression-webpack-plugin')
7+
webpackPlugins.push(new CompressionPlugin({
8+
algorithm: 'gzip',
9+
test: /\.js$|\.html$|\.css$|\.jpg$|\.jpeg$|\.png/, // 需要压缩的文件类型
10+
threshold: 10240, // 归档需要进行压缩的文件大小最小值,我这个是10K以上的进行压缩
11+
deleteOriginalAssets: false, // 是否删除原文件
12+
minRatio: 0.5
13+
}))
14+
}
515
function resolve(dir) {
616
return path.join(__dirname, dir)
717
}
@@ -46,7 +56,8 @@ module.exports = {
4656
alias: {
4757
'@': resolve('src')
4858
}
49-
}
59+
},
60+
plugins: webpackPlugins
5061
},
5162
chainWebpack(config) {
5263
// it can improve the speed of the first screen, it is recommended to turn on preload
@@ -88,7 +99,7 @@ module.exports = {
8899
.plugin('ScriptExtHtmlWebpackPlugin')
89100
.after('html')
90101
.use('script-ext-html-webpack-plugin', [{
91-
// `runtime` must same as runtimeChunk name. default is `runtime`
102+
// `runtime` must same as runtimeChunk name. default is `runtime`
92103
inline: /runtime\..*\.js$/
93104
}])
94105
.end()

0 commit comments

Comments
 (0)