From eabd43ce882ffdc156c8382ed5f30aad78f58e4a Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 1 Nov 2022 09:26:30 +0800 Subject: [PATCH] change webpack config to reduce size --- package.json | 2 +- vue.config.js | 23 ++++++++++++++++++++++- yarn.lock | 23 +++++++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 36170c38..1599f721 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,6 @@ "ts-loader": "8.2.0", "typescript": "^4.6.4", "vue-template-compiler": "2.x", - "webpack-bundle-analyzer": "^4.5.0" + "webpack-bundle-analyzer": "^4.7.0" } } diff --git a/vue.config.js b/vue.config.js index 1ee5584c..cf73ba74 100644 --- a/vue.config.js +++ b/vue.config.js @@ -3,7 +3,6 @@ const path = require('path') const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') // const CompressionWebpackPlugin = require('compression-webpack-plugin') const NodePolyfillPlugin = require('node-polyfill-webpack-plugin') - // const productionGzipExtensions = ['js', 'css'] module.exports = { @@ -19,6 +18,28 @@ module.exports = { }, }, configureWebpack: { + optimization: { + runtimeChunk: 'single', + splitChunks: { + chunks: 'all', + maxInitialRequests: Infinity, + minSize: 120000, + maxSize: 250000, + cacheGroups: { + vendor: { + test: /node_modules/, + name() { + // get the name. E.g. node_modules/packageName/not/this/part.js + // or node_modules/packageName + // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/) + + // npm package names are URL-safe, but some servers don't like @ symbols + return 'ping.pub.chunks' + }, + }, + }, + }, + }, resolve: { alias: { '@themeConfig': path.resolve(__dirname, 'themeConfig.js'), diff --git a/yarn.lock b/yarn.lock index 3124c86e..5fc70333 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4126,9 +4126,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001335: - version "1.0.30001341" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz#59590c8ffa8b5939cf4161f00827b8873ad72498" - integrity sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA== + version "1.0.30001427" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001427.tgz" + integrity sha512-lfXQ73oB9c8DP5Suxaszm+Ta2sr/4tf8+381GkIm1MLj/YdLf+rEDyDSRCzeltuyTVGm+/s18gdZ0q+Wmp8VsQ== case-sensitive-paths-webpack-plugin@^2.3.0: version "2.4.0" @@ -10106,7 +10106,7 @@ webidl-conversions@^4.0.2: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg== -webpack-bundle-analyzer@^4.4.0, webpack-bundle-analyzer@^4.5.0: +webpack-bundle-analyzer@^4.4.0: version "4.5.0" resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.5.0.tgz#1b0eea2947e73528754a6f9af3e91b2b6e0f79d5" integrity sha512-GUMZlM3SKwS8Z+CKeIFx7CVoHn3dXFcUAjT/dcZQQmfSZGvitPfMob2ipjai7ovFFqPvTqkEZ/leL4O0YOdAYQ== @@ -10121,6 +10121,21 @@ webpack-bundle-analyzer@^4.4.0, webpack-bundle-analyzer@^4.5.0: sirv "^1.0.7" ws "^7.3.1" +webpack-bundle-analyzer@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.7.0.tgz#33c1c485a7fcae8627c547b5c3328b46de733c66" + integrity sha512-j9b8ynpJS4K+zfO5GGwsAcQX4ZHpWV+yRiHDiL+bE0XHJ8NiPYLTNVQdlFYWxtpg9lfAQNlwJg16J9AJtFSXRg== + dependencies: + acorn "^8.0.4" + acorn-walk "^8.0.0" + chalk "^4.1.0" + commander "^7.2.0" + gzip-size "^6.0.0" + lodash "^4.17.20" + opener "^1.5.2" + sirv "^1.0.7" + ws "^7.3.1" + webpack-chain@^6.0.0, webpack-chain@^6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-6.5.1.tgz#4f27284cbbb637e3c8fbdef43eef588d4d861206"