-
-
Notifications
You must be signed in to change notification settings - Fork 446
/
vite.shared.config.ts
49 lines (42 loc) · 1.08 KB
/
vite.shared.config.ts
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
/** @fileoverview The common config for frontend projects. */
import { Rollup, UserConfig } from 'vite';
export const manualChunks: Rollup.GetManualChunk = (id, { getModuleInfo }) => {
const hasReactDependency = (id: string): boolean => {
return getModuleInfo(id)
?.importedIds
.some((importedId) =>
importedId.includes('react') ||
importedId.includes('react-dom')
) ?? false;
}
// Caution: React-related packages should be bundled together otherwise it will cause runtime errors
if (id.includes('/node_modules/') && hasReactDependency(id)) {
return 'react';
}
if (id.includes('/@logto/')) {
return '@logto';
}
if (id.includes('/node_modules/')) {
return 'vendors';
}
const match = /\/lib\/locales\/([^/]+)/.exec(id);
if (match?.[1]) {
return `phrases-${match[1]}`;
}
};
export const defaultConfig: UserConfig = {
resolve: {
alias: [
{
find: /^@\//,
replacement: '/src/',
},
],
},
build: {
sourcemap: true,
rollupOptions: {
output: { manualChunks },
},
},
};