Skip to content

Commit

Permalink
Support Vite 3
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Aug 17, 2022
1 parent 1295639 commit e03c8cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/react-server-dom-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"node": ">=0.10.0"
},
"peerDependencies": {
"react": "^17.0.0",
"vite": "^2.7.1"
"react": "^17.0.0 || ^18.0.0",
"vite": "^2.7.1 || ^3.0.7"
},
"dependencies": {
"es-module-lexer": "^0.9.3",
Expand Down
13 changes: 9 additions & 4 deletions packages/react-server-dom-vite/src/ReactFlightVitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
// $FlowFixMe[module-missing]
import {init, parse} from 'es-module-lexer';
import MagicString from 'magic-string';
// $FlowFixMe[module-missing]
import {normalizePath, transformWithEsbuild, createServer} from 'vite';

import {promises as fs} from 'fs';
import path from 'path';

// $FlowFixMe[module-missing]
import * as vite from 'vite';
const {normalizePath, transformWithEsbuild, createServer} = vite;
const isVite3 = vite.version && vite.version.startsWith('3.');

type PluginOptions = {
serverBuildEntries: string[],
optimizeBoundaries: boolean | 'build',
Expand Down Expand Up @@ -351,7 +354,8 @@ async function findClientBoundariesForClientBuild(
const server = await createServer({
root,
clearScreen: false,
server: {middlewareMode: 'ssr'},
server: {middlewareMode: isVite3 ? true : 'ssr', hmr: false},
appType: 'custom',
});

try {
Expand Down Expand Up @@ -380,7 +384,8 @@ const hashImportsPlugin = {
function(_, imports) {
return imports
.trim()
.replace(/"([^"]+?)":/gm, function(__, relativePath) {
.replace(/"([^"]+?)":/gm, function(all, relativePath) {
if (relativePath === '__VITE_PRELOAD__') return all;
const absolutePath = path.resolve(
path.dirname(id.split('?')[0]),
relativePath,
Expand Down

0 comments on commit e03c8cc

Please sign in to comment.