-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathvite.config.ts
51 lines (49 loc) · 1.21 KB
/
vite.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
50
51
/// <reference types="vitest" />
import react from '@vitejs/plugin-react-swc';
import { Plugin, loadEnv } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { defineConfig } from 'vitest/config';
export default defineConfig(({ mode }) => {
return {
plugins: [react(), envPlugin(), nodePolyfills()],
esbuild: {},
root: 'src',
publicDir: '../public',
build: {
sourcemap: true,
outDir: '../build',
rollupOptions: {
onwarn(warning, defaultHandler) {
// See: https://github.com/vitejs/vite/issues/15012
if (warning.code === 'SOURCEMAP_ERROR') {
return;
}
defaultHandler(warning);
},
},
},
server: {
port: 3000,
},
test: {
globals: true,
environment: 'happy-dom',
},
};
});
function envPlugin(): Plugin {
return {
name: 'env-plugin',
config(_, { mode }) {
const env = loadEnv(mode, '.', ['REACT_APP_', 'NODE_ENV']);
return {
define: Object.fromEntries(
Object.entries(env).map(([key, value]) => [
`import.meta.env.${key}`,
JSON.stringify(value),
])
),
};
},
};
}