Skip to content

Commit a2ee33b

Browse files
committed
Revert "feat(vite): auto-detect client entry (#4059)"
This reverts commit bfbb207.
1 parent 66a0a97 commit a2ee33b

5 files changed

Lines changed: 38 additions & 48 deletions

File tree

examples/vite-ssr-preact/vite.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ import preact from "@preact/preset-vite";
44

55
export default defineConfig({
66
plugins: [nitro(), preact()],
7+
environments: {
8+
client: {
9+
build: {
10+
rollupOptions: {
11+
input: "./src/entry-client.tsx",
12+
},
13+
},
14+
},
15+
},
716
});

examples/vite-ssr-react/vite.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ import react from "@vitejs/plugin-react";
44

55
export default defineConfig({
66
plugins: [nitro(), react()],
7+
environments: {
8+
client: {
9+
build: { rollupOptions: { input: "./src/entry-client.tsx" } },
10+
},
11+
},
712
});

examples/vite-ssr-solid/vite.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ import { nitro } from "nitro/vite";
55
export default defineConfig({
66
plugins: [solid({ ssr: true }), nitro()],
77
esbuild: { jsx: "preserve", jsxImportSource: "solid-js" },
8+
environments: {
9+
ssr: {
10+
build: { rollupOptions: { input: "./src/entry-server.tsx" } },
11+
},
12+
client: {
13+
build: { rollupOptions: { input: "./src/entry-client.tsx" } },
14+
},
15+
},
816
});

examples/vite-ssr-vue-router/vite.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { nitro } from "nitro/vite";
55

66
export default defineConfig((_env) => ({
77
plugins: [patchVueExclude(vue(), /\?assets/), devtoolsJson(), nitro()],
8+
environments: {
9+
client: { build: { rollupOptions: { input: "./app/entry-client.ts" } } },
10+
ssr: { build: { rollupOptions: { input: "./app/entry-server.ts" } } },
11+
},
812
}));
913

1014
// Workaround https://github.com/vitejs/vite-plugin-vue/issues/677

src/build/vite/plugin.ts

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -100,50 +100,17 @@ function nitroEnv(ctx: NitroPluginContext): VitePlugin {
100100
...createServiceEnvironments(ctx),
101101
nitro: createNitroEnvironment(ctx),
102102
};
103-
104-
let clientEntry: string | undefined;
105-
let clientEntryConfigured = !!getEntry(
106-
userConfig.environments?.client?.build?.rolldownOptions?.input ||
107-
userConfig.environments?.client?.build?.rollupOptions?.input
108-
);
109-
if (!clientEntryConfigured) {
110-
const rendererTemplate = useNitro(ctx).options.renderer?.template;
111-
if (rendererTemplate) {
112-
// Use Nitro renderer template as client entry
113-
clientEntry = rendererTemplate;
114-
ctx.nitro!.logger.info(
115-
`Using Nitro renderer template \`${prettyPath(rendererTemplate)}\` as vite client entry.`
116-
);
117-
} else {
118-
// Auto-detect client entry
119-
clientEntry = resolveModulePath("./entry-client", {
120-
try: true,
121-
extensions: DEFAULT_EXTENSIONS,
122-
from: ["app", "src", ""].flatMap((d) =>
123-
[ctx.nitro!.options.rootDir, ...ctx.nitro!.options.scanDirs].map(
124-
(s) => join(s, d) + "/"
125-
)
126-
),
127-
});
128-
if (clientEntry) {
129-
ctx.nitro!.logger.info(`Using \`${prettyPath(clientEntry)}\` as vite client entry.`);
130-
}
131-
}
132-
}
133-
if (clientEntry) {
134-
environments.client = {
135-
consumer: userConfig.environments?.client?.consumer ?? "client",
136-
build: clientEntryConfigured
137-
? undefined
138-
: {
139-
rollupOptions: {
140-
input: clientEntry ? { index: clientEntry } : undefined,
141-
},
142-
},
143-
};
144-
debug("[env] Environments:", Object.keys(environments).join(", "));
145-
}
146-
103+
environments.client = {
104+
consumer: userConfig.environments?.client?.consumer ?? "client",
105+
build: {
106+
rollupOptions: {
107+
input:
108+
userConfig.environments?.client?.build?.rollupOptions?.input ??
109+
useNitro(ctx).options.renderer?.template,
110+
},
111+
},
112+
};
113+
debug("[env] Environments:", Object.keys(environments).join(", "));
147114
return {
148115
environments,
149116
};
@@ -417,10 +384,7 @@ async function setupNitroContext(
417384
ctx.nitro!.logger.info(`Using \`${prettyPath(ssrEntry)}\` as vite ssr entry.`);
418385
}
419386
} else {
420-
let ssrEntry = getEntry(
421-
userConfig.environments.ssr.build?.rolldownOptions?.input ||
422-
userConfig.environments.ssr.build?.rollupOptions?.input
423-
);
387+
let ssrEntry = getEntry(userConfig.environments.ssr.build?.rollupOptions?.input);
424388
if (typeof ssrEntry === "string") {
425389
ssrEntry =
426390
resolveModulePath(ssrEntry, {

0 commit comments

Comments
 (0)