Skip to content

Commit

Permalink
feat: 生产环境开启gzip打包
Browse files Browse the repository at this point in the history
  • Loading branch information
yulimchen committed Jul 12, 2021
1 parent c100b1a commit c73a060
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"babel-plugin-import": "^1.13.0",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"compression-webpack-plugin": "5.0.1",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0",
"less": "^3.12.2",
Expand Down
15 changes: 12 additions & 3 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const autoprefixer = require('autoprefixer')
const pxtoviewport = require('postcss-px-to-viewport')
const cdnDependencies = require('./dependencies-cdn')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const path = require('path')
function resolve(dir) {
Expand Down Expand Up @@ -37,6 +38,16 @@ module.exports = {
}
if (process.env.NODE_ENV === 'production') {
configNew.externals = externals
configNew.plugins = [
// gzip
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false
})
]
}
return configNew
},
Expand All @@ -55,9 +66,7 @@ module.exports = {
}
},
chainWebpack: (config) => {
/**
* 添加 CDN 参数到 htmlWebpackPlugin 配置中
*/
// 添加 CDN 参数到 htmlWebpackPlugin 配置中
const targetHtmlPluginNames = ['html']
targetHtmlPluginNames.forEach((name) => {
config.plugin(name).tap(options => {
Expand Down

0 comments on commit c73a060

Please sign in to comment.