Skip to content

Commit 1278edd

Browse files
authored
chore(fullstack): move reactHmrPreamblePlugin to each example (#1201)
Let's push this to upstream vitejs/vite-plugin-react#890
1 parent 22d0582 commit 1278edd

File tree

6 files changed

+69
-47
lines changed

6 files changed

+69
-47
lines changed

packages/fullstack/examples/basic/vite.config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import fullstack, {
2-
reactHmrPreamblePlugin,
3-
} from "@hiogawa/vite-plugin-fullstack";
1+
import fullstack from "@hiogawa/vite-plugin-fullstack";
42
// import inspect from "vite-plugin-inspect";
53
import react from "@vitejs/plugin-react";
6-
import { defineConfig } from "vite";
4+
import { type Plugin, defineConfig } from "vite";
75

86
export default defineConfig((_env) => ({
97
clearScreen: false,
@@ -42,3 +40,18 @@ export default defineConfig((_env) => ({
4240
},
4341
},
4442
}));
43+
44+
// waiting for https://github.com/vitejs/vite-plugin-react/pull/890
45+
function reactHmrPreamblePlugin(): Plugin[] {
46+
return [
47+
{
48+
name: "react-hmr-preamble",
49+
resolveId: (id) =>
50+
id === "virtual:react-hmr-preamble" ? "\0" + id : null,
51+
load: (id) =>
52+
id === "\0virtual:react-hmr-preamble"
53+
? react.preambleCode.replace("__BASE__", "/")
54+
: null,
55+
},
56+
];
57+
}

packages/fullstack/examples/cloudflare/vite.config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { cloudflare } from "@cloudflare/vite-plugin";
2-
import fullstack, {
3-
reactHmrPreamblePlugin,
4-
} from "@hiogawa/vite-plugin-fullstack";
2+
import fullstack from "@hiogawa/vite-plugin-fullstack";
53
import react from "@vitejs/plugin-react";
6-
import { defineConfig } from "vite";
4+
import { type Plugin, defineConfig } from "vite";
75

86
export default defineConfig((_env) => ({
97
clearScreen: false,
@@ -47,3 +45,18 @@ export default defineConfig((_env) => ({
4745
},
4846
},
4947
}));
48+
49+
// waiting for https://github.com/vitejs/vite-plugin-react/pull/890
50+
function reactHmrPreamblePlugin(): Plugin[] {
51+
return [
52+
{
53+
name: "react-hmr-preamble",
54+
resolveId: (id) =>
55+
id === "virtual:react-hmr-preamble" ? "\0" + id : null,
56+
load: (id) =>
57+
id === "\0virtual:react-hmr-preamble"
58+
? react.preambleCode.replace("__BASE__", "/")
59+
: null,
60+
},
61+
];
62+
}

packages/fullstack/examples/island/vite.config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import fullstack, {
2-
reactHmrPreamblePlugin,
3-
} from "@hiogawa/vite-plugin-fullstack";
1+
import fullstack from "@hiogawa/vite-plugin-fullstack";
42
import react from "@vitejs/plugin-react";
5-
import { defineConfig } from "vite";
3+
import { type Plugin, defineConfig } from "vite";
64

75
export default defineConfig((_env) => ({
86
clearScreen: false,
@@ -40,3 +38,18 @@ export default defineConfig((_env) => ({
4038
},
4139
},
4240
}));
41+
42+
// waiting for https://github.com/vitejs/vite-plugin-react/pull/890
43+
function reactHmrPreamblePlugin(): Plugin[] {
44+
return [
45+
{
46+
name: "react-hmr-preamble",
47+
resolveId: (id) =>
48+
id === "virtual:react-hmr-preamble" ? "\0" + id : null,
49+
load: (id) =>
50+
id === "\0virtual:react-hmr-preamble"
51+
? react.preambleCode.replace("__BASE__", "/")
52+
: null,
53+
},
54+
];
55+
}

packages/fullstack/examples/react-router/vite.config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import fullstack, {
2-
reactHmrPreamblePlugin,
3-
} from "@hiogawa/vite-plugin-fullstack";
1+
import fullstack from "@hiogawa/vite-plugin-fullstack";
42
// import inspect from "vite-plugin-inspect";
53
import react from "@vitejs/plugin-react";
6-
import { defineConfig } from "vite";
4+
import { type Plugin, defineConfig } from "vite";
75
import devtoolsJson from "vite-plugin-devtools-json";
86

97
export default defineConfig((_env) => ({
@@ -44,3 +42,18 @@ export default defineConfig((_env) => ({
4442
},
4543
},
4644
}));
45+
46+
// waiting for https://github.com/vitejs/vite-plugin-react/pull/890
47+
function reactHmrPreamblePlugin(): Plugin[] {
48+
return [
49+
{
50+
name: "react-hmr-preamble",
51+
resolveId: (id) =>
52+
id === "virtual:react-hmr-preamble" ? "\0" + id : null,
53+
load: (id) =>
54+
id === "\0virtual:react-hmr-preamble"
55+
? react.preambleCode.replace("__BASE__", "/")
56+
: null,
57+
},
58+
];
59+
}

packages/fullstack/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export { default, assetsPlugin } from "./plugin.ts";
2-
export { reactHmrPreamblePlugin } from "./plugins/react.ts";
1+
export { default, serverHandlerPlugin, assetsPlugin } from "./plugin.ts";

packages/fullstack/src/plugins/react.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)