-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvite.config.js
More file actions
134 lines (131 loc) · 3.93 KB
/
vite.config.js
File metadata and controls
134 lines (131 loc) · 3.93 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* eslint-disable lodash/prefer-lodash-method */
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { visualizer } from 'rollup-plugin-visualizer'
import { getGitInfo } from './scripts/gitInfo.js'
const DEFAULT_PORT = 3030
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
const isDev = mode === 'development'
const isStaging = mode === 'staging'
const minifyInDev = env.VITE_MINIFY_DEV === 'true'
return {
base: env.VITE_BASE_URL || '/',
define: {
// Inject build-time constants
__APP_MODE__: JSON.stringify(mode),
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
},
css: {
devSourcemap: true,
},
server: {
port: Number(env.PORT) || DEFAULT_PORT,
open: true,
warmup: {
clientFiles: [
'./src/App.tsx',
'./src/index.tsx',
'./src/router/**/*.js',
'./src/Theme/**/*.js',
],
},
proxy: {
'/api': 'http://localhost:3000',
'/auth': 'http://localhost:3000',
'/oauth': 'http://localhost:3000',
'/pub': 'http://localhost:3000',
'/ws': { target: 'ws://localhost:3000', ws: true },
},
},
optimizeDeps: {
include: [
'hoist-non-react-statics',
'react',
'react-dom',
'react-redux',
'@reduxjs/toolkit',
'styled-components',
'react-router-dom',
],
exclude: isDev || isStaging ? ['@sentry/react', '@sentry/cli'] : [],
esbuildOptions: {
mainFields: ['module', 'main'],
target: 'esnext',
loader: { '.js': 'jsx' },
},
force: minifyInDev,
},
plugins: [
react({ babel: { babelrc: true, configFile: true } }),
visualizer({
filename: 'stats.html',
open: !!process.env.BUNDLE_ANALYZE,
gzipSize: true,
brotliSize: true,
}),
{
name: 'vite:git-revision',
config() {
return { define: { GIT_INFO: JSON.stringify(getGitInfo()) } }
},
},
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
src: fileURLToPath(new URL('./src', import.meta.url)),
},
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.d.ts', '.json'],
},
esbuild: {
loader: 'tsx',
include: /src\/.*\.(jsx?|tsx?)$/,
sourcemap: isDev,
// Dev minify is optional; off by default for better DX.
...(minifyInDev && {
minify: true,
}),
// Drop console and debugger only in production builds
...(!isDev && {
drop: ['console', 'debugger'],
}),
},
build: {
outDir: 'build',
// Prefer esbuild for speed unless you need terser features:
minify: 'esbuild',
sourcemap: isDev || isStaging ? true : 'hidden',
chunkSizeWarningLimit: 800,
target: 'es2020',
modulePreload: { polyfill: false },
cssCodeSplit: true,
// Use lightningcss only if installed; otherwise omit:
cssMinify: 'lightningcss',
commonjsOptions: {
transformMixedEsModules: true,
include: [/react-gauge-chart/, /node_modules/],
// Avoid esmExternals:true unless you know you need it.
},
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('LazyComponent')) return 'lazy-loaded-component'
if (id.includes('@sentry')) return 'sentry'
if (
id.includes('chart.js') ||
id.includes('react-chartjs-2') ||
id.includes('chartjs-adapter-date-fns') ||
id.includes('chartjs-plugin-datalabels') ||
id.includes('chartjs-plugin-zoom') ||
id.includes('lightweight-charts')
) return 'charts'
},
compact: true,
exports: 'auto',
},
},
},
}
})