Skip to content

Commit 500eaac

Browse files
committed
feat: 前端打包增加分包策略
1 parent 28e8540 commit 500eaac

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

km-console/packages/layout-clusters-fe/config/CoverHtmlWebpackPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ class CoverHtmlWebpackPlugin {
8686

8787
assetJson.reverse().forEach((item) => {
8888
if (/\.js$/.test(item)) {
89-
// if (item.includes('vendor~')) {
90-
// vendors += `<script async src="${item}"></script>`;
91-
// } else {
92-
// TODO: entry 只有一个
93-
portalMap['@portal/layout'] = item;
94-
// }
89+
if (item.includes('vendor~')) {
90+
vendors += `<script async src="${item}"></script>`;
91+
} else {
92+
// TODO: entry 只有一个
93+
portalMap['@portal/layout'] = item;
94+
}
9595
} else if (/\.css$/.test(item)) {
9696
links += `<link href="${item}" rel="stylesheet">`;
9797
}

km-console/packages/layout-clusters-fe/config/d1-webpack.base.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const TerserJSPlugin = require('terser-webpack-plugin');
99
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
1010
const theme = require('./theme');
1111
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
12-
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
1312

1413
const isProd = process.env.NODE_ENV === 'production';
1514
const babelOptions = {
@@ -43,7 +42,6 @@ const babelOptions = {
4342
module.exports = () => {
4443
const cssFileName = isProd ? '[name]-[chunkhash].css' : '[name].css';
4544
const plugins = [
46-
// !isProd && new HardSourceWebpackPlugin(),
4745
new CoverHtmlWebpackPlugin(),
4846
new ProgressBarPlugin(),
4947
new CaseSensitivePathsPlugin(),
@@ -150,23 +148,21 @@ module.exports = () => {
150148
],
151149
},
152150
optimization: Object.assign(
153-
// {
154-
// splitChunks: {
155-
// cacheGroups: {
156-
// vendor: {
157-
// test: /[\\/]node_modules[\\/]/,
158-
// chunks: 'all',
159-
// name: 'vendor',
160-
// priority: 10,
161-
// enforce: true,
162-
// minChunks: 1,
163-
// maxSize: 3500000,
164-
// },
165-
// },
166-
// },
167-
// },
168151
isProd
169152
? {
153+
splitChunks: {
154+
cacheGroups: {
155+
vendor: {
156+
test: /[\\/]node_modules[\\/]/,
157+
chunks: 'all',
158+
name: 'vendor',
159+
priority: 10,
160+
enforce: true,
161+
minChunks: 1,
162+
maxSize: 3000000,
163+
},
164+
},
165+
},
170166
minimizer: [
171167
new TerserJSPlugin({
172168
cache: true,

0 commit comments

Comments
 (0)