Skip to content

Commit

Permalink
refactor: flip browser and ssr build
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jun 5, 2024
1 parent 197bae4 commit be83031
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/react-server/examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build --ssr",
"preview": "vite preview",
"test-e2e": "playwright test",
"test-e2e-preview": "E2E_PREVIEW=1 playwright test",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/examples/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build --ssr",
"preview": "vite preview",
"cf-build": "SSR_ENTRY=/src/adapters/cloudflare-workers.ts pnpm build && bash misc/cloudflare-workers/build.sh",
"cf-preview": "cd misc/cloudflare-workers && wrangler dev",
Expand Down
16 changes: 5 additions & 11 deletions packages/react-server/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export function vitePluginReactServer(options?: {
},
};

// orchestrate four builds from a single vite (browser) build
// orchestrate four builds from a single vite (ssr) build
const buildOrchestrationPlugin: Plugin = {
name: vitePluginReactServer.name + ":build",
apply: "build",
Expand All @@ -306,24 +306,18 @@ export function vitePluginReactServer(options?: {
console.log("▶▶▶ REACT SERVER BUILD (scan) [1/4]");
manager.buildType = "scan";
await build(reactServerViteConfig);

console.log("▶▶▶ REACT SERVER BUILD (server) [2/4]");
manager.buildType = "rsc";
manager.rscUseClientIds.clear();
await build(reactServerViteConfig);

console.log("▶▶▶ REACT SERVER BUILD (browser) [3/4]");
manager.buildType = "client";
}
},
async closeBundle() {
// TODO: build ssr only when client build succeeds
if (manager.buildType === "client") {
await build();

console.log("▶▶▶ REACT SERVER BUILD (ssr) [4/4]");
manager.buildType = "ssr";
await build({
build: {
ssr: true,
},
});
}
},
};
Expand Down

0 comments on commit be83031

Please sign in to comment.