Commit 4cca00717692ab8b68a1c7dd985a2821a28ec5db
1 parent
81e90409
test(code-split): code split optimization
Showing
3 changed files
with
39 additions
and
5 deletions
CHANGELOG.zh_CN.md
build/vite/optimizer.ts
0 → 100644
1 | +import type { GetManualChunk, GetManualChunkApi } from 'rollup'; | |
2 | + | |
3 | +// | |
4 | +const vendorLibs: { match: string[]; output: string }[] = [ | |
5 | + { | |
6 | + match: ['xlsx'], | |
7 | + output: 'xlsx', | |
8 | + }, | |
9 | +]; | |
10 | + | |
11 | +// @ts-ignore | |
12 | +export const configManualChunk: GetManualChunk = (id: string, api: GetManualChunkApi) => { | |
13 | + if (/[\\/]node_modules[\\/]/.test(id)) { | |
14 | + const matchItem = vendorLibs.find((item) => { | |
15 | + const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig'); | |
16 | + return reg.test(id); | |
17 | + }); | |
18 | + return matchItem ? matchItem.output : null; | |
19 | + } | |
20 | +}; | ... | ... |
vite.config.ts
... | ... | @@ -3,6 +3,7 @@ import { resolve } from 'path'; |
3 | 3 | |
4 | 4 | import { modifyVars } from './build/config/lessModifyVars'; |
5 | 5 | import { createProxy } from './build/vite/proxy'; |
6 | +import { configManualChunk } from './build/vite/optimizer'; | |
6 | 7 | |
7 | 8 | import globbyTransform from './build/vite/plugin/transform/globby'; |
8 | 9 | import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import'; |
... | ... | @@ -53,9 +54,11 @@ const viteConfig: UserConfig = { |
53 | 54 | // terser options |
54 | 55 | terserOptions: { |
55 | 56 | compress: { |
57 | + keep_infinity: true, | |
56 | 58 | drop_console: VITE_DROP_CONSOLE, |
57 | 59 | }, |
58 | 60 | }, |
61 | + | |
59 | 62 | define: { |
60 | 63 | __VERSION__: pkg.version, |
61 | 64 | // setting vue-i18-next |
... | ... | @@ -64,12 +67,14 @@ const viteConfig: UserConfig = { |
64 | 67 | __VUE_I18N_FULL_INSTALL__: false, |
65 | 68 | __INTLIFY_PROD_DEVTOOLS__: false, |
66 | 69 | }, |
70 | + | |
67 | 71 | cssPreprocessOptions: { |
68 | 72 | less: { |
69 | 73 | modifyVars: modifyVars, |
70 | 74 | javascriptEnabled: true, |
71 | 75 | }, |
72 | 76 | }, |
77 | + | |
73 | 78 | // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache |
74 | 79 | optimizeDeps: { |
75 | 80 | include: [ |
... | ... | @@ -80,11 +85,6 @@ const viteConfig: UserConfig = { |
80 | 85 | ], |
81 | 86 | }, |
82 | 87 | |
83 | - proxy: createProxy(VITE_PROXY), | |
84 | - plugins: createVitePlugins(viteEnv), | |
85 | - rollupInputOptions: { | |
86 | - plugins: createRollupPlugin(), | |
87 | - }, | |
88 | 88 | transforms: [ |
89 | 89 | globbyTransform({ |
90 | 90 | resolvers: resolvers, |
... | ... | @@ -94,6 +94,19 @@ const viteConfig: UserConfig = { |
94 | 94 | }), |
95 | 95 | dynamicImportTransform(VITE_DYNAMIC_IMPORT), |
96 | 96 | ], |
97 | + | |
98 | + proxy: createProxy(VITE_PROXY), | |
99 | + | |
100 | + plugins: createVitePlugins(viteEnv), | |
101 | + | |
102 | + rollupInputOptions: { | |
103 | + plugins: createRollupPlugin(), | |
104 | + }, | |
105 | + | |
106 | + rollupOutputOptions: { | |
107 | + compact: true, | |
108 | + manualChunks: configManualChunk, | |
109 | + }, | |
97 | 110 | }; |
98 | 111 | |
99 | 112 | export default viteConfig; | ... | ... |