-
Notifications
You must be signed in to change notification settings - Fork 631
Expand file tree
/
Copy pathvite.config.mjs
More file actions
80 lines (76 loc) · 1.77 KB
/
vite.config.mjs
File metadata and controls
80 lines (76 loc) · 1.77 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
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const srcRoot = path.resolve(__dirname, 'src');
const srcDirectoryAliases = fs
.readdirSync(srcRoot, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => ({
find: entry.name,
replacement: path.resolve(srcRoot, entry.name),
}));
export default defineConfig(({ mode }) => ({
base: mode === 'production' ? '/react-material-admin/' : '/',
plugins: [
react({
parserConfig: (id) => {
if (id.endsWith('.ts')) {
return { syntax: 'typescript', tsx: false };
}
if (id.endsWith('.tsx')) {
return { syntax: 'typescript', tsx: true };
}
if (id.endsWith('.js') || id.endsWith('.jsx')) {
return { syntax: 'ecmascript', jsx: true };
}
return undefined;
},
}),
],
build: {
outDir: 'build',
},
css: {
preprocessorOptions: {},
},
esbuild: {
loader: 'jsx',
include: /src\/.*\.[jt]sx?$/,
exclude: [],
},
resolve: {
alias: [
{ find: '@', replacement: srcRoot },
...srcDirectoryAliases,
],
},
define: {
global: 'globalThis',
'process.env': '{}',
'process.env.NODE_ENV': JSON.stringify(mode),
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
},
define: {
global: 'globalThis',
},
},
},
server: {
port: 3000,
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.js',
css: true,
fileParallelism: false,
},
}));