Skip to content

Commit 84ada98

Browse files
committed
perf: reduce bundle size
1 parent 14ac440 commit 84ada98

17 files changed

Lines changed: 16545 additions & 63550 deletions

config/config.github.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { defineConfig } from '@umijs/max';
22
import path from 'path';
3+
import { configureSplitChunks } from './splitChunks';
34
// import { routes } from './routes';
45

56
export default defineConfig({
67
chainWebpack(config) {
8+
configureSplitChunks(config);
79
config.module
810
.rule('cesium')
911
.test(/\.js$/)
@@ -19,6 +21,7 @@ export default defineConfig({
1921
},
2022
define: {
2123
CESIUM_BASE_URL: '/umi-react-admin/Cesium',
24+
CESIUM_ION_TOKEN: process.env.CESIUM_ION_TOKEN,
2225
},
2326
favicons: ['/umi-react-admin/favicon.ico'],
2427
base: '/umi-react-admin/',

config/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { defineConfig } from '@umijs/max';
22
// import path from 'path';
33
import { routes } from './routes';
4+
import { configureSplitChunks } from './splitChunks';
45

56
export default defineConfig({
7+
chainWebpack(config) {
8+
configureSplitChunks(config);
9+
},
610
copy: [
711
{
812
from: 'node_modules/cesium/Build/Cesium/Workers',

config/splitChunks.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
type SplitChunksOptions = {
2+
chunks: 'all';
3+
minSize: number;
4+
maxSize: number;
5+
cacheGroups: Record<string, unknown>;
6+
};
7+
8+
type WebpackChainConfig = {
9+
optimization: {
10+
splitChunks: (options: SplitChunksOptions) => void;
11+
};
12+
};
13+
14+
export const configureSplitChunks = (config: WebpackChainConfig) => {
15+
config.optimization.splitChunks({
16+
chunks: 'all',
17+
minSize: 30_000,
18+
maxSize: 240_000,
19+
cacheGroups: {
20+
framework: {
21+
name: 'framework',
22+
test: /[\\/]node_modules[\\/](react|react-dom|scheduler|history)[\\/]/,
23+
priority: 50,
24+
enforce: true,
25+
},
26+
charts: {
27+
name: 'vendor-charts',
28+
test: /[\\/]node_modules[\\/](@antv|d3|@ant-design[\\/](charts|plots))[\\/]/,
29+
priority: 45,
30+
enforce: true,
31+
maxSize: 240_000,
32+
},
33+
antd: {
34+
name: 'vendor-antd',
35+
test: /[\\/]node_modules[\\/](@ant-design|antd|rc-.+)[\\/]/,
36+
priority: 40,
37+
enforce: true,
38+
maxSize: 240_000,
39+
},
40+
cesium: {
41+
name: 'vendor-cesium',
42+
test: /[\\/]node_modules[\\/](cesium|cesium-navigation-es6)[\\/]/,
43+
priority: 35,
44+
enforce: true,
45+
},
46+
designable: {
47+
name: 'vendor-designable',
48+
test: /[\\/]node_modules[\\/](@designable|@pind|@formily)[\\/]/,
49+
priority: 30,
50+
enforce: true,
51+
maxSize: 240_000,
52+
},
53+
pdf: {
54+
name: 'vendor-pdf',
55+
test: /[\\/]node_modules[\\/](react-pdf|pdfjs-dist)[\\/]/,
56+
priority: 25,
57+
enforce: true,
58+
maxSize: 240_000,
59+
},
60+
media: {
61+
name: 'vendor-media',
62+
test: /[\\/]node_modules[\\/](artplayer|wavesurfer\.js|xgplayer|xgplayer-music|html2canvas|tinymce)[\\/]/,
63+
priority: 20,
64+
enforce: true,
65+
maxSize: 240_000,
66+
},
67+
turf: {
68+
name: 'vendor-turf',
69+
test: /[\\/]node_modules[\\/](@turf|geojson-rbush|rbush)[\\/]/,
70+
priority: 20,
71+
enforce: true,
72+
},
73+
vendors: {
74+
name: 'vendors',
75+
test: /[\\/]node_modules[\\/]/,
76+
priority: -10,
77+
reuseExistingChunk: true,
78+
maxSize: 240_000,
79+
},
80+
},
81+
});
82+
};

0 commit comments

Comments
 (0)