-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathvite.config.ts
More file actions
64 lines (62 loc) · 1.96 KB
/
vite.config.ts
File metadata and controls
64 lines (62 loc) · 1.96 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import fs from 'fs';
// https://vitejs.dev/config/
export default defineConfig(async () => {
// In codesandbox, we won't have the packages folder
// We ignore errors in this case
const aliases: Record<string, string> = {};
try {
const packages = fs.readdirSync(
path.resolve(__dirname, '../../packages')
);
for (const dirName of packages) {
if (dirName === 'create-react-admin') continue;
const packageJson = JSON.parse(
fs.readFileSync(
path.resolve(
__dirname,
'../../packages',
dirName,
'package.json'
),
'utf8'
)
);
aliases[packageJson.name] = path.resolve(
__dirname,
`../../packages/${packageJson.name}/src`
);
}
} catch {
/* empty */
}
return {
plugins: [react()],
resolve: {
preserveSymlinks: true,
alias: [
// The 2 next aliases are needed to avoid having multiple MUI instances
{
find: '@mui/material',
replacement: path.resolve(
__dirname,
'node_modules/@mui/material'
),
},
{
find: '@mui/icons-material',
replacement: path.resolve(
__dirname,
'node_modules/@mui/icons-material'
),
},
...Object.keys(aliases).map(packageName => ({
find: packageName,
replacement: aliases[packageName],
})),
],
},
};
});