-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
30 lines (24 loc) · 893 Bytes
/
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
import { defineConfig, loadEnv } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import react from '@vitejs/plugin-react';
// Since Jest does not support Vite's import.meta out of the box yet
// but only with heavy configuration changes like experimental ESM support, Babel etc.,
// we instead "re-enable" process.env like outlined here:
// https://github.com/vitejs/vite/issues/1149#issuecomment-857686209
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
// expose .env as process.env instead of import.meta since jest does not import meta yet
const envWithProcessPrefix = Object.entries(env).reduce(
(prev, [key, val]) => {
return {
...prev,
[`process.env.${key}`]: `"${val}"`,
};
},
{},
);
return {
define: envWithProcessPrefix,
plugins: [tsconfigPaths(), react()],
};
});