Skip to content

Commit ae706ce

Browse files
yaminyassinYamin Yassin
andauthored
Support Vite 8 in the setup guide and example app (#486)
* Upgrade vite-app example to Vite 8 @vitejs/plugin-react@6 no longer runs Babel, so the react-strict-dom preset now runs through vite-plugin-babel with an explicit include that also covers example-ui. Switch to the native resolve.tsconfigPaths and optimizeDeps.rolldownOptions, and drop vite-tsconfig-paths. * Update Vite setup guide for Vite 8 Lead with the Vite 8 setup and keep Vite 7 below as just the differences. Explain why the preset must run through vite-plugin-babel when @vitejs/plugin-react@6 drops Babel. --------- Co-authored-by: Yamin Yassin <Yamin.Yassin+CAG@cagtechhub.com>
1 parent c4e69e0 commit ae706ce

5 files changed

Lines changed: 560 additions & 651 deletions

File tree

apps/vite-app/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
"example-ui": "0.0.55",
1414
"react": "^19.2.0",
1515
"react-dom": "^19.2.0",
16-
"vite-plugin-babel": "^1.3.2",
16+
"vite-plugin-babel": "^1.7.1",
1717
"react-strict-dom": "0.0.55"
1818
},
1919
"devDependencies": {
2020
"autoprefixer": "^10.4.22",
21-
"vite-tsconfig-paths": "^5.1.4",
2221
"@eslint/js": "^9.39.1",
2322
"@types/node": "^24.10.1",
2423
"@types/react": "^19.2.5",
2524
"@types/react-dom": "^19.2.3",
26-
"@vitejs/plugin-react": "^5.1.1",
25+
"@vitejs/plugin-react": "^6.0.2",
2726
"eslint": "^9.39.1",
2827
"eslint-plugin-react-hooks": "^7.0.1",
2928
"eslint-plugin-react-refresh": "^0.4.24",
3029
"globals": "^16.5.0",
3130
"typescript": "~5.9.3",
3231
"typescript-eslint": "^8.46.4",
33-
"vite": "^7.2.4"
32+
"vite": "^8.0.13"
3433
}
3534
}

apps/vite-app/postcss.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ export default {
44
plugins: {
55
'react-strict-dom/postcss-plugin': {
66
include: [
7-
'src/**/*.{js,jsx,ts,tsx}',
8-
'../../node_modules/example-ui/**/*.jsx'
7+
'src/**/*.{js,jsx,mjs,ts,tsx}',
8+
'../../node_modules/example-ui/**/*.{js,jsx,mjs}'
99
],
10-
babelConfig
10+
babelConfig,
11+
useLayers: true
1112
},
1213
autoprefixer: {}
1314
}

apps/vite-app/vite.config.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
import { defineConfig } from "vite";
2-
import react from "@vitejs/plugin-react";
3-
import tsConfigPaths from "vite-tsconfig-paths";
4-
import babel from "vite-plugin-babel";
2+
import viteReact from "@vitejs/plugin-react";
3+
import viteBabel from "vite-plugin-babel";
54

65
const webOnlyExtensions = [".web.js", ".web.jsx", ".web.ts", ".web.tsx"];
6+
const allExtensions = [
7+
...webOnlyExtensions,
8+
".mjs",
9+
".js",
10+
".mts",
11+
".ts",
12+
".jsx",
13+
".tsx",
14+
".json",
15+
];
16+
17+
// On Vite 8, @vitejs/plugin-react@6 no longer runs Babel, so vite-plugin-babel
18+
// must apply react-strict-dom/babel-preset to app source and to any package
19+
// that ships React Strict DOM UI (here, example-ui).
20+
const babelInclude = [
21+
/[\\/]src[\\/]/,
22+
/[\\/]example-ui[\\/]/,
23+
/[\\/]react-strict-dom[\\/]/,
24+
];
725

826
export default defineConfig(() => ({
9-
resolve: {
10-
extensions: [
11-
...webOnlyExtensions,
12-
".mjs",
13-
".js",
14-
".mts",
15-
".ts",
16-
".jsx",
17-
".tsx",
18-
".json",
19-
],
20-
},
2127
plugins: [
22-
tsConfigPaths(),
23-
react({
24-
babel: {
25-
configFile: true,
26-
},
28+
viteReact(),
29+
viteBabel({
30+
include: babelInclude,
31+
filter: /\.[cm]?[jt]sx?$/,
2732
}),
28-
babel(),
2933
],
34+
resolve: {
35+
// Native in Vite 8 — replaces the vite-tsconfig-paths plugin.
36+
tsconfigPaths: true,
37+
extensions: allExtensions,
38+
},
39+
optimizeDeps: {
40+
// Vite 8's dependency optimizer is Rolldown, not esbuild.
41+
rolldownOptions: {
42+
resolve: { extensions: allExtensions },
43+
},
44+
},
3045
}));

0 commit comments

Comments
 (0)