Skip to content

Commit e03c8cc

Browse files
committed
Support Vite 3
1 parent 1295639 commit e03c8cc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/react-server-dom-vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"node": ">=0.10.0"
5555
},
5656
"peerDependencies": {
57-
"react": "^17.0.0",
58-
"vite": "^2.7.1"
57+
"react": "^17.0.0 || ^18.0.0",
58+
"vite": "^2.7.1 || ^3.0.7"
5959
},
6060
"dependencies": {
6161
"es-module-lexer": "^0.9.3",

packages/react-server-dom-vite/src/ReactFlightVitePlugin.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
// $FlowFixMe[module-missing]
1111
import {init, parse} from 'es-module-lexer';
1212
import MagicString from 'magic-string';
13-
// $FlowFixMe[module-missing]
14-
import {normalizePath, transformWithEsbuild, createServer} from 'vite';
1513

1614
import {promises as fs} from 'fs';
1715
import path from 'path';
1816

17+
// $FlowFixMe[module-missing]
18+
import * as vite from 'vite';
19+
const {normalizePath, transformWithEsbuild, createServer} = vite;
20+
const isVite3 = vite.version && vite.version.startsWith('3.');
21+
1922
type PluginOptions = {
2023
serverBuildEntries: string[],
2124
optimizeBoundaries: boolean | 'build',
@@ -351,7 +354,8 @@ async function findClientBoundariesForClientBuild(
351354
const server = await createServer({
352355
root,
353356
clearScreen: false,
354-
server: {middlewareMode: 'ssr'},
357+
server: {middlewareMode: isVite3 ? true : 'ssr', hmr: false},
358+
appType: 'custom',
355359
});
356360

357361
try {
@@ -380,7 +384,8 @@ const hashImportsPlugin = {
380384
function(_, imports) {
381385
return imports
382386
.trim()
383-
.replace(/"([^"]+?)":/gm, function(__, relativePath) {
387+
.replace(/"([^"]+?)":/gm, function(all, relativePath) {
388+
if (relativePath === '__VITE_PRELOAD__') return all;
384389
const absolutePath = path.resolve(
385390
path.dirname(id.split('?')[0]),
386391
relativePath,

0 commit comments

Comments
 (0)