Skip to content

Run Astro as a regular Vite plugin (astro/vite) - #18121

Draft
matthewp wants to merge 8 commits into
mainfrom
spike/astro-vite-plugin
Draft

matthewp wants to merge 8 commits into
mainfrom
spike/astro-vite-plugin

Conversation

@matthewp

Copy link
Copy Markdown
Contributor

Changes

  • Adds astro() from astro/vite, so Astro runs as a regular Vite plugin: no Astro CLI, no astro.config.mjs. The Astro config, integrations included, is passed inline, and vite, vite build and vite preview do the work. Spike, draft only.
  • Setup runs eagerly when astro() is called, because Vite collects plugins before its config hooks run: integration hooks run, then createVite, as in the CLI. The command is inferred from NODE_ENV, or passed explicitly with defineConfig((env) => ({ plugins: [astro(config, env)] })). A config hook throws if the guess doesn't match Vite's real command.
  • Vite's builder re-evaluates vite.config once per build environment, so the build-mode setup is cached per project root and cleared in buildApp. Integration hooks run once, and every environment shares one set of plugin instances.
  • Integration server and build hooks map to Vite hooks:
    • astro:server:start/done → httpServer listening/close
    • astro:build:done → buildApp post
  • Content collections and .astro/ types work in dev and build. The dev content setup moves out of core/dev/dev.ts into content/dev-setup.ts, and the plugin reuses it.
  • Session telemetry is recorded from configureServer, buildApp and configurePreviewServer, not when the config is evaluated. Session events get a new source: 'cli' | 'vite-plugin' field.
  • Small core refactors so the plugins work outside the CLI:
    • Plugins can read command from Vite.
    • Route info, env mode and private env are resolved lazily.
    • static-build.ts exposes the build environment config.
  • Works: .astro pages, React islands, live updates in dev, SSR with @astrojs/node, actions, astro:env, content collections, ClientRouter, and other Vite plugins alongside (Tailwind in the example).
  • Known gaps:
    • vite preview for SSR output.
    • Integrations see vite preview as build.
    • Astro's server.* options.
    • Fonts server teardown after build.
    • CLI-only commands (add, check, sync).

Testing

  • Adds examples/vite-plugin-react, which uses @astrojs/react, a content collection and Tailwind, run with vite / vite build / vite preview.
  • Adds eventCliSession() unit tests for the source field.

Docs

  • None yet. This is an experimental spike; docs follow if the direction is accepted.

@changeset-bot

changeset-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 685dbd9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@matthewp matthewp added the pr preview Apply this label to a PR to generate a preview release label Sep 24, 2026
@github-actions github-actions Bot added the semver: minor Change triggers a `minor` release label Sep 24, 2026

@github-actions github-actions Bot left a comment

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.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@github-actions github-actions Bot added pkg: example Related to an example package (scope) pkg: astro Related to the core `astro` package (scope) labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

e18e dependency analysis

No dependency warnings found.

# Conflicts:
#	packages/astro/src/core/build/static-build.ts
@codspeed

codspeed Bot commented Sep 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing spike/astro-vite-plugin (685dbd9) with main (2b8b2e8)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (c17d920) during the generation of this report, so 2b8b2e8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@matthewp matthewp added pr preview Apply this label to a PR to generate a preview release and removed pr preview Apply this label to a PR to generate a preview release labels Sep 24, 2026
@github-actions github-actions Bot removed the pr preview Apply this label to a PR to generate a preview release label Sep 24, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/astro@18121

commit: 685dbd9

This branch has not been deployed

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

Labels

pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) semver: minor Change triggers a `minor` release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant