Skip to content

Commit ffb9dc6

Browse files
committed
feat: 添加分包
1 parent 7437ecf commit ffb9dc6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

vite.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ export default defineConfig(configEnv => {
1818
const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview;
1919
return {
2020
base: viteEnv.VITE_BASE_URL,
21+
build: {
22+
rollupOptions: {
23+
output: {
24+
assetFileNames: chunkInfo => {
25+
const name = chunkInfo.name;
26+
27+
if (name?.endsWith('.css')) {
28+
return 'css/[name]-[hash].css';
29+
}
30+
31+
const imgExts = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'];
32+
33+
if (imgExts.some(ext => name?.endsWith(`.${ext}`))) {
34+
return 'images/[name]-[hash].[ext]';
35+
}
36+
37+
return 'assets/[name]-[hash].[ext]';
38+
},
39+
chunkFileNames: 'js/[name]-[hash].js',
40+
entryFileNames: 'js/[name]-[hash].js',
41+
manualChunks: {
42+
animate: ['motion'],
43+
antd: ['antd', '@ant-design/v5-patch-for-react-19'],
44+
axios: ['axios'],
45+
react: ['react', 'react-dom', 'react-error-boundary'],
46+
reactRouter: ['react-router-dom'],
47+
redux: ['react-redux', '@reduxjs/toolkit'],
48+
sa: ['@sa/axios', '@sa/color', '@sa/hooks', '@sa/materials', '@sa/utils']
49+
}
50+
}
51+
}
52+
},
2153
css: {
2254
preprocessorOptions: {
2355
scss: {

0 commit comments

Comments
 (0)