Skip to content

feat(build): run lifecycle through Vite - #3377

Draft
james-elicx wants to merge 28 commits into
codex/shared-build-lifecyclefrom
codex/vite-build-lifecycle
Draft

james-elicx wants to merge 28 commits into
codex/shared-build-lifecyclefrom
codex/vite-build-lifecycle

Conversation

@james-elicx

@james-elicx james-elicx commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • connect the shared lifecycle to full direct Vite CLI builds, including global options before the command
  • keep watch, targeted/SSR, ordinary programmatic, and nested Vite builds outside the top-level lifecycle
  • preserve configured prerender concurrency, resolved user plugins, custom output roots, and production semantics
  • isolate the auxiliary hybrid Pages bundle in its own named environment

Compatibility boundary

Vite evaluates config imports before plugin hooks. A config dependency that reads dotenv or NODE_ENV before the vinext import cannot be initialized by this plugin; move that read behind explicit Vite loadEnv in an early config dependency. The open review threads track this tradeoff of using direct Vite without wrapper-side initialization.

Validation

  • Vite command contract and invocation tests
  • prerender configuration tests
  • vp check
  • vp run vinext#build

PR 3 of 7.

@james-elicx
james-elicx added this pull request to stack #3382 September 22, 2026 11:37
@pkg-pr-new

pkg-pr-new Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@3377

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@3377

@vinext/types

npm i https://pkg.pr.new/@vinext/types@3377

vinext

npm i https://pkg.pr.new/vinext@3377

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@3377

commit: 023b79a

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues\n\nTime limit: 8 minutes. Complete the review and post all findings within that limit.

@github-actions

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
response-store-demo preview production
workers-cache preview production
kv preview production
static-export preview production
web preview production

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 023b79a against base 1f61de6 using alternating same-runner rounds. Next.js was unchanged and skipped.

1 improved · 0 regressed · 5 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 142.3 KB 142.3 KB ⚫ -0.0%
Client entry size (gzip) vinext 129.7 KB 129.7 KB ⚫ -0.0%
Dev server cold start vinext 3.29 s 3.23 s 🟢 -1.9%
Production build time vinext 3.79 s 3.77 s ⚫ -0.7%
RSC entry closure size (gzip) vinext 127.9 KB 127.8 KB ⚫ -0.1%
Server bundle size (gzip) vinext 226.0 KB 225.9 KB ⚫ -0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

Comment thread packages/vinext/src/utils/vite-cli-invocation.ts Outdated
Comment thread packages/vinext/src/index.ts Outdated
Comment thread packages/vinext/src/config/prerender.ts
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 3 actionable inline findings.

github run

@james-elicx
james-elicx force-pushed the codex/vite-build-lifecycle branch from 078c7d0 to ab7311c Compare September 22, 2026 11:51
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues\n\nTime limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/build/lifecycle.ts Outdated
Comment thread packages/vinext/src/build/lifecycle.ts Outdated
Comment thread packages/vinext/src/build/lifecycle.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 3 actionable inline findings.

github run

@james-elicx
james-elicx force-pushed the codex/vite-build-lifecycle branch from ab7311c to 86e2104 Compare September 22, 2026 12:16
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/utils/vite-cli-invocation.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding. Targeted tests pass after rebuilding vinext.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues\n\nTime limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/index.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding.

github run

@james-elicx
james-elicx force-pushed the codex/vite-build-lifecycle branch from 7f41ce5 to 9341cf4 Compare September 22, 2026 12:44
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues\n\nTime limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/build/lifecycle.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding.

github run

@james-elicx
james-elicx force-pushed the codex/vite-build-lifecycle branch from 9341cf4 to ae580bb Compare September 22, 2026 13:06
@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/index.ts Outdated
Comment thread packages/vinext/src/build/lifecycle.ts
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 2 actionable inline findings. Targeted unit tests pass.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

No new actionable findings beyond the existing inline review comments.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

No new actionable findings beyond the existing inline review comments.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/index.ts
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding. CI also reproduces the regression.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/index.ts
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding. Targeted CLI invocation tests pass.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

if (!viteCliBuildConfigNodeEnv) {
Reflect.set(process.env, "NODE_ENV", "production");
}
loadDotenv({ root: earlyViteCliInvocation.root, mode: earlyViteCliInvocation.mode });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This eager load runs before Vite resolves envDir, so it loads the CLI root even when the project config sets envDir: false or points at a different directory. Since loadDotenv() never overwrites existing keys, the later config hook cannot correct values loaded from the wrong directory; a workspace .env.production can therefore override the app env, and envDir: false no longer disables vinext dotenv loading for direct CLI builds. Please defer mutation until the resolved env policy is known, or undo/reload the eager values once config resolves.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deliberate pre-config compatibility boundary. Before this PR, vinext dev/build loaded root dotenv before evaluating vite.config, including when the eventual config set custom envDir or false; the migration contract explicitly preserves that behavior for both command spellings. Waiting for resolved envDir would break apps reading process.env while the config module is evaluated. The README now says custom envDir requires explicit Vite loadEnv to supply config-time values. I am leaving this thread visible for maintainer review of that tradeoff.

Comment thread packages/vinext/src/index.ts
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 2 actionable inline findings.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

Comment thread packages/vinext/src/build/lifecycle.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 1 actionable inline finding.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

if (!viteCliBuildConfigNodeEnv) {
Reflect.set(process.env, "NODE_ENV", "production");
}
loadDotenv({ root: earlyViteCliInvocation.root, mode: earlyViteCliInvocation.mode });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This module side effect still runs too late for dependencies imported before vinext from the Vite config. With the supported --configLoader runner, a config such as import "./config-helper"; import vinext from "vinext" evaluates the helper first, so any module-scope read of process.env there sees neither .env.production nor the production NODE_ENV; only evaluating the later vinext import performs this load. The previous vinext build path initialized the environment before Vite loaded the config graph. Please move direct-CLI initialization ahead of config module evaluation (rather than relying on the position of the vinext import), or otherwise preserve dotenv/NODE_ENV for the whole config dependency graph.

Comment thread packages/vinext/src/index.ts Outdated
@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Posted 2 actionable inline findings. Targeted lifecycle and CLI tests pass.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues

Time limit: 8 minutes. Complete the review and post all findings within that limit.

@ask-bonk

ask-bonk Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant