Skip to content

Commit 14767fc

Browse files
authored
perf: move resolve of runtime code into a "pre" plugin (#79)
1 parent a948dc1 commit 14767fc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ const react = (_options?: Options): PluginOption[] => {
5656
};
5757

5858
return [
59+
{
60+
name: "vite:react-swc:resolve-runtime",
61+
apply: "serve",
62+
enforce: "pre", // Run before Vite default resolve to avoid syscalls
63+
resolveId: (id) => (id === runtimePublicPath ? id : undefined),
64+
load: (id) =>
65+
id === runtimePublicPath
66+
? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8")
67+
: undefined,
68+
},
5969
{
6070
name: "vite:react-swc",
6171
apply: "serve",
@@ -65,11 +75,6 @@ const react = (_options?: Options): PluginOption[] => {
6575
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
6676
},
6777
}),
68-
resolveId: (id) => (id === runtimePublicPath ? id : undefined),
69-
load: (id) =>
70-
id === runtimePublicPath
71-
? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8")
72-
: undefined,
7378
transformIndexHtml: (_, config) => [
7479
{
7580
tag: "script",

0 commit comments

Comments
 (0)