forked from marmelab/react-admin-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
57 lines (55 loc) · 1.63 KB
/
Copy pathvite.config.ts
File metadata and controls
57 lines (55 loc) · 1.63 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
import react from '@vitejs/plugin-react';
import path from 'path';
import fs from 'fs';
import { defineConfig } from 'vite';
/**
* https://vitejs.dev/config/
* @type { import('vite').UserConfig }
*/
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 {}
return {
plugins: [react()],
resolve: {
alias: [
{
find: /^@mui\/icons-material\/(.*)/,
replacement: '@mui/icons-material/esm/$1',
},
...Object.keys(aliases).map(packageName => ({
find: packageName,
replacement: aliases[packageName],
})),
],
},
server: {
port: 8080,
},
define: { 'process.env': {} },
};
});