-
Notifications
You must be signed in to change notification settings - Fork 505
Expand file tree
/
Copy pathvite.config.ts
More file actions
99 lines (94 loc) · 3.87 KB
/
vite.config.ts
File metadata and controls
99 lines (94 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { type ConfigEnv, defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import replace from '@rollup/plugin-replace';
import * as path from 'path';
const normalizeModuleId = (id: string) => id.replace(/\\/g, '/');
const vendorChunkRules: Array<[chunkName: string, matches: (normalizedId: string) => boolean]> = [
// NOTE: We deliberately do NOT define a `vendor-web3` chunk here. Forcing
// every Web3 dependency into one giant chunk causes Rollup to hoist shared
// helpers (notably Vite's auto-generated `__vitePreload`) into that chunk,
// which makes the entry statically depend on it. The browser then preloads
// ~2 MB / 650 KB-gz of Solana code on first paint even for users who never
// visit a payment page. Letting Rollup pick natural chunk boundaries keeps
// Web3 code split across small chunks that are only fetched lazily by
// `utils/x402/solana.ts` and `plugins/solana-wallets.ts`.
//
// Same rationale applies to `element-plus`: although every consumer in `src`
// uses selective `import { ElButton } from 'element-plus'` (so tree-shaking
// is already at work), forcing all retained components into a single shared
// chunk lumps ~115 component subtrees (570 KB / 180 KB-gz) onto the entry's
// static graph, because dozens of routes statically import from it. Letting
// Rollup do the splitting naturally keeps each component family in a small
// chunk co-located with its consumer route. The eager critical path then
// only carries the few components that App.vue / Layouts / `vLoading`
// actually need (ElConfigProvider, ElTag, ElIcon, ElDialog/Overlay/…).
['vendor-vue-router', (id) => id.includes('/vue-router/')],
['vendor-vue', (id) => id.includes('/node_modules/vue/') || id.includes('/node_modules/@vue/')],
['vendor-codemirror', (id) => id.includes('/codemirror/') || id.includes('/@codemirror/')],
['vendor-katex', (id) => id.includes('/katex/')],
['vendor-highlight', (id) => id.includes('/highlight.js/')],
['vendor-chart', (id) => id.includes('/chart.js/') || id.includes('/vue-chartjs/')],
['vendor-axios', (id) => id.includes('/axios/')],
['vendor-dayjs', (id) => id.includes('/dayjs/')]
];
export default defineConfig((config: ConfigEnv) => {
process.env = { ...process.env, ...loadEnv(config.mode, process.cwd()) };
return {
server: {
host: 'localhost',
port: 8084,
proxy: {
'/api/v1/auth': {
target: process.env.VITE_BASE_URL_AUTH,
changeOrigin: true
},
'/api/v1/users': {
target: process.env.VITE_BASE_URL_AUTH,
changeOrigin: true
},
'/sso/v1/token': {
target: process.env.VITE_BASE_URL_AUTH,
changeOrigin: true
},
'/api': {
target: process.env.VITE_BASE_URL_PLATFORM,
changeOrigin: true
},
'/static': {
target: process.env.VITE_BASE_URL_PLATFORM,
changeOrigin: true
}
}
},
plugins: [
vue(),
replace({
preventAssignment: true
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
build: {
// Computing gzip size for ~10 MB of chunks blows past the 2 GB V8
// heap on Cloudflare Workers Builds. The report is stdout-only,
// so disabling it costs nothing functional and shaves ~15 s off
// every build (also resolves the OOM crash at the
// `computing gzip size` step).
reportCompressedSize: false,
rollupOptions: {
output: {
manualChunks(id) {
const normalizedId = normalizeModuleId(id);
if (!normalizedId.includes('/node_modules/')) return;
const matched = vendorChunkRules.find(([, matches]) => matches(normalizedId));
if (matched) return matched[0];
return undefined;
}
}
}
}
};
});