-
Notifications
You must be signed in to change notification settings - Fork 22
/
vite.config.mjs
117 lines (112 loc) · 3.39 KB
/
vite.config.mjs
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
import { codecovVitePlugin } from '@codecov/vite-plugin'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
import { ViteEjsPlugin } from 'vite-plugin-ejs'
import svgr from 'vite-plugin-svgr'
import legacy from '@vitejs/plugin-legacy'
import { ViteReactSourcemapsPlugin } from '@acemarke/react-prod-sourcemaps'
export default defineConfig((config) => {
const env = loadEnv(config.mode, process.cwd(), 'REACT_APP')
const envWithProcessPrefix = {
'process.env': `${JSON.stringify(env)}`,
}
const plugins = []
if (
process.env.CODECOV_API_URL &&
process.env.CODECOV_ORG_TOKEN &&
process.env.UPLOAD_CODECOV_BUNDLE_STATS === 'true'
) {
plugins.push(
codecovVitePlugin({
enableBundleAnalysis:
process.env.UPLOAD_CODECOV_BUNDLE_STATS === 'true',
bundleName: process.env.CODECOV_BUNDLE_NAME,
apiUrl: process.env.CODECOV_API_URL,
uploadToken: process.env.CODECOV_ORG_TOKEN,
})
)
}
const runSentryPlugin =
config.mode === 'production' && !!process.env.SENTRY_AUTH_TOKEN
if (runSentryPlugin) {
plugins.push(
ViteReactSourcemapsPlugin({
debug: false,
preserve: false,
}),
sentryVitePlugin({
applicationKey: 'gazebo',
org: process.env.SENTRY_ORG || 'codecov',
project: process.env.REACT_APP_SENTRY_PROJECT || 'gazebo',
authToken: process.env.SENTRY_AUTH_TOKEN,
release: {
name: process.env.GAZEBO_SHA,
deploy: {
env:
process.env.REACT_APP_SENTRY_ENVIRONMENT || process.env.NODE_ENV,
},
},
})
)
}
return {
server: {
port: 3000,
},
build: {
outDir: 'build',
sourcemap: runSentryPlugin,
rollupOptions: {
output: {
entryFileNames: 'assets/[name].[hash:21].js',
chunkFileNames: 'assets/[name].[hash:21].js',
assetFileNames: 'assets/[name].[hash:21][extname]',
manualChunks: {
vendor_react: ['react', 'react-dom', 'react/jsx-runtime'],
vendor_react_router: [
'react-router',
'react-router-dom',
'react-router-dom-v5-compat',
],
vendor_date_fns: ['date-fns'],
vendor_lodash: [
'lodash/get',
'lodash/isEqual',
'lodash/isNull',
'lodash/isNil',
'lodash/isEmpty',
'lodash/isString',
'lodash/isNumber',
'lodash/isBoolean',
'lodash/isUndefined',
'lodash/isArray',
'lodash/gt',
'lodash/omit',
'lodash/flatMap',
'lodash/groupBy',
],
},
},
},
},
define: envWithProcessPrefix,
plugins: [
ViteEjsPlugin({
isProduction: process.env.REACT_APP_ENV === 'production',
REACT_APP_PENDO_KEY: process.env.REACT_APP_PENDO_KEY,
}),
tsconfigPaths(),
legacy({
// which legacy browsers to support
targets: ['>0.2%', 'not dead', 'not op_mini all'],
// which polyfills to include in the modern build
modernPolyfills: ['es.promise.all-settled'],
}),
react(),
svgr(),
...plugins,
],
}
})