Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Document how to have sourcemaps in production #10466

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions docs/Vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ export default defineConfig({
});
```

## Sourcemaps in production

By default, Vite won't include the TypeScript sourcemaps in production builds. This means you'll only have the react-admin ESM builds for debugging.
Should you prefer to have the TypeScript sources, you'll have to configure some Vite aliases:

```tsx
// in vite.config.ts
import { defineConfig } from "vite";
import path from "path";
import react from "@vitejs/plugin-react";

const alias = [
{ find: 'react-admin', replacement: path.resolve(__dirname, './node_modules/react-admin/src') },
{ find: 'ra-core', replacement: path.resolve(__dirname, './node_modules/ra-core/src') },
{ find: 'ra-ui-materialui', replacement: path.resolve(__dirname, './node_modules/ra-ui-materialui/src') },
// add any other react-admin packages you have
]

export default defineConfig({
plugins: [react()],
build: { sourcemap: true },
resolve: { alias },
});
```

## Troubleshooting

### Error about `global` Being `undefined`
Expand Down
52 changes: 43 additions & 9 deletions packages/create-react-admin/templates/common/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

const alias = [
{ find: "react-admin", replacement: "./node_modules/react-admin/src" },
{ find: "ra-core", replacement: "./node_modules/ra-core/src" },
{
find: "ra-ui-materialui",
replacement: "./node_modules/ra-ui-materialui/src",
},
{
find: "ra-i18n-polyglot",
replacement: "./node_modules/ra-i18n-polyglot/src",
},
{
find: "ra-language-english",
replacement: "./node_modules/ra-language-english/src",
},
{
find: "ra-data-json-server",
replacement: "./node_modules/ra-data-json-server/src",
},
{
find: "ra-data-simple-rest",
replacement: "./node_modules/ra-data-simple-rest/src",
},
{
find: "ra-data-fakerest",
replacement: "./node_modules/ra-data-fakerest/src",
},
// add any other react-admin packages you have
];

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: true,
},
base: './',
});
export default defineConfig(({ mode }) => ({
plugins: [react()],
server: {
host: true,
},
build: {
sourcemap: mode === "developement",
},
resolve: { alias },
base: "./",
}));
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,44 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

const alias = [
{ find: "react-admin", replacement: "./node_modules/react-admin/src" },
{ find: "ra-core", replacement: "./node_modules/ra-core/src" },
{
find: "ra-ui-materialui",
replacement: "./node_modules/ra-ui-materialui/src",
},
{
find: "ra-i18n-polyglot",
replacement: "./node_modules/ra-i18n-polyglot/src",
},
{
find: "ra-language-english",
replacement: "./node_modules/ra-language-english/src",
},
{
find: "ra-data-json-server",
replacement: "./node_modules/ra-data-json-server/src",
},
{
find: "ra-data-simple-rest",
replacement: "./node_modules/ra-data-simple-rest/src",
},
{
find: "ra-data-fakerest",
replacement: "./node_modules/ra-data-fakerest/src",
},
// add any other react-admin packages you have
];

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
host: true,
},
base: './',
resolve: { alias },
test: {
globals: true,
environment: 'jsdom'
Expand Down
Loading