Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 58 additions & 22 deletions examples/tutorial/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,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({
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'
),
},
],
},
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],
})),
],
},
};
});
Loading