-
Notifications
You must be signed in to change notification settings - Fork 17
/
vite.config.ts
73 lines (70 loc) · 2.34 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { defineConfig } from 'vite';
import path from 'path';
import fs from 'fs';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
import preserveDirectives from 'rollup-preserve-directives';
// https://vitejs.dev/config/
export default defineConfig(async () => {
const aliases: Record<string, string> = {};
if (fs.existsSync(path.resolve(__dirname, '../packages'))) {
const packages = fs.readdirSync(path.resolve(__dirname, '../packages'));
for (const dirName of packages) {
if (dirName === 'create-react-admin') continue;
// eslint-disable-next-line prettier/prettier
const packageJson = await import(
path.resolve(__dirname, '../packages', dirName, 'package.json'),
{ assert: { type: 'json' } }
);
aliases[packageJson.default.name] = path.resolve(
__dirname,
`${path.resolve('../')}/packages/${
packageJson.default.name.split('@react-admin/')[1]
}/src`
);
}
}
return {
plugins: [
react(),
visualizer({
open: process.env.NODE_ENV !== 'CI',
filename: './build/stats.html',
}),
],
define: {
'process.env': process.env,
},
server: {
port: 8000,
open: true,
},
base: './',
esbuild: {
keepNames: true,
},
build: {
outDir: 'build',
sourcemap: true,
rollupOptions: {
plugins: [preserveDirectives()],
},
},
resolve: {
preserveSymlinks: true,
alias: [
// allow profiling in production
{ find: /^react-dom$/, replacement: 'react-dom/profiling' },
{
find: 'scheduler/tracing',
replacement: 'scheduler/tracing-profiling',
},
// we need to manually follow the symlinks for local packages to allow deep HMR
...Object.keys(aliases).map(packageName => ({
find: packageName,
replacement: aliases[packageName],
})),
],
},
};
});