-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
66 lines (63 loc) · 2.04 KB
/
Copy pathvite.config.ts
File metadata and controls
66 lines (63 loc) · 2.04 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
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, loadEnv } from 'vite';
import addScriptPlugin from './add-script-plugin.ts';
const env = loadEnv('app', process.cwd(), '');
const base = env.PUBLIC_BASE_PATH || '';
const href = env.PUBLIC_BASE_HREF || '';
const outputVisualizer = env.OUTPUT_VISUALIZER === 'true';
// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
return {
base,
build: {
chunkSizeWarningLimit: 1256,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
notFound: resolve(__dirname, '404.html'),
},
output: {
manualChunks(id) {
if (id.includes('highlight.js')) {
return 'highlight';
} else if (id.includes('react-dom')) {
return 'react-dom';
} else if (id.includes('@remix-run') || id.includes('react-router-dom') || id.includes('react-router')) {
return 'react-router';
}
},
},
},
},
define: {
__APP_PUBLIC_BASE_HREF__: JSON.stringify(href),
__APP_PUBLIC_BASE_PATH__: JSON.stringify(base),
},
plugins: [
react(),
outputVisualizer &&
visualizer({
emitFile: true,
filename: 'stats.html',
}),
command === 'build' && addScriptPlugin(),
],
resolve: {
alias: {
'@assets': resolve(__dirname, 'src/assets'),
'@components': resolve(__dirname, 'src/components'),
'@contexts': resolve(__dirname, 'src/contexts'),
'@hocs': resolve(__dirname, 'src/hocs'),
'@hooks': resolve(__dirname, 'src/hooks'),
'@lib': resolve(__dirname, 'lib'),
'@pages': resolve(__dirname, 'src/pages'),
'@src': resolve(__dirname, 'src'),
'@store': resolve(__dirname, 'src/store'),
'@tools': resolve(__dirname, 'src/tools'),
'@types': resolve(__dirname, 'src/types'),
},
},
};
});