Skip to content

feat: allow adapters to pass a function for vite config - #16986

Merged
teemingc merged 5 commits into
version-3from
adapter-vite-function
Sep 1, 2026
Merged

feat: allow adapters to pass a function for vite config#16986
teemingc merged 5 commits into
version-3from
adapter-vite-function

Conversation

@ottomated

@ottomated ottomated commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

For adapter-cloudflare, we need to add @cloudflare/vite-plugin to the vite.plugins array. However, while configuring the plugin, we need access to svelte_config.out_dir in order to tell it how to generate the wrangler config.

This plugin allows adapters to do

  vite: ({ config }) => ({
    plugins: [
      some_plugin_that_requires(config),
    ]
  }

Drive-by, also allows adapters to just specify a plugins array if they don't need to specify pre and post. This is backwards-compatible.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Summary by CodeRabbit

  • New Features
    • Adapters can now configure Vite plugins dynamically using the validated SvelteKit configuration.
    • Added support for defining adapter Vite plugins as an ordered list or separate pre/post groups.
    • Expanded public adapter configuration types and documentation.
  • Bug Fixes
    • Improved handling and ordering of adapter-provided Vite plugins.
  • Documentation
    • Documented adapter Vite configuration options and plugin ordering.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 31, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 0c1556e:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/0c1556ea1e5fb00cff14e219af3f0bbdb84a02ee

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16986

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0c1556e

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit 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

@svelte-docs-bot

Copy link
Copy Markdown

@teemingc teemingc added the adapters - general Support for functionality general to all adapters label Aug 31, 2026
Comment on lines +85 to +102
* Vite plugins injected by the adapter. By default,
* they are placed before SvelteKit's plugins.
* @since 3.0.0
*/
plugins?:
| Plugin[]
| {
/**
* Vite plugins placed before any of SvelteKit's own plugins.
* @since 3.0.0
*/
pre?: Plugin[];
/**
* Vite plugins placed after any of SvelteKit's own plugins.
* @since 3.0.0
*/
post?: Plugin[];
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel a little conflicted about having the single array option default to pre. I kind of liked the explicitness of pre and post.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think pre and post are only needed in very rare situations; it would be confusing to adapter authors if we required the specificity when it actually doesn't matter most of the time.

Comment thread .changeset/fifty-breads-judge.md Outdated
Comment thread packages/kit/src/exports/public.d.ts Outdated
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 90057581-97c0-4664-823f-0dab8f363677

📥 Commits

Reviewing files that changed from the base of the PR and between 737984a and 0c1556e.

📒 Files selected for processing (7)
  • .changeset/fifty-breads-judge.md
  • packages/adapter-cloudflare/index.js
  • packages/kit/src/core/config/index.js
  • packages/kit/src/exports/public.d.ts
  • packages/kit/src/exports/vite/index.js
  • packages/kit/src/types/internal.d.ts
  • packages/kit/types/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/kit/src/exports/vite/index.js
  • .changeset/fifty-breads-judge.md
  • packages/adapter-cloudflare/index.js
  • packages/kit/types/index.d.ts
  • packages/kit/src/core/config/index.js
  • packages/kit/src/exports/public.d.ts
  • packages/kit/src/types/internal.d.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

SvelteKit now supports adapter Vite configuration callbacks that receive the validated configuration. Vite plugin arrays are normalized as pre plugins, and the Cloudflare adapter uses this format.

Changes

Adapter Vite configuration

Layer / File(s) Summary
Adapter Vite configuration contract
packages/kit/src/exports/public.d.ts, packages/kit/types/index.d.ts, packages/kit/src/types/internal.d.ts
Adapter.vite accepts static configuration or a callback receiving ValidatedConfig. The exported AdapterViteConfig interface defines request, response, and ordered plugin options.
Validated adapter configuration
packages/kit/src/core/config/index.js
validate_config invokes adapter.vite callbacks with the validated configuration and stores the returned options.
Vite plugin normalization and adapter wiring
packages/kit/src/exports/vite/index.js, packages/adapter-cloudflare/index.js, .changeset/fifty-breads-judge.md
Array-valued plugins are normalized into pre plugins. The Cloudflare adapter passes its virtual-workers plugin as an array. A minor release changeset documents the update.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0c155

This PR adds the requested adapter configuration flexibility and remains merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant Adapter
  participant validate_config
  participant Vite
  participant PluginAssembly
  Adapter->>validate_config: provide adapter.vite callback
  validate_config->>Adapter: request validated configuration
  Adapter-->>validate_config: return AdapterViteConfig
  validate_config->>Vite: store resolved Vite configuration
  Vite->>PluginAssembly: normalize plugin array as pre plugins
  PluginAssembly-->>Vite: assemble ordered plugins
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adapters can provide Vite configuration through a function.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch adapter-vite-function

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Comment @coderabbitai help to get the list of available commands.

@teemingc
teemingc merged commit 03f1687 into version-3 Sep 1, 2026
41 checks passed
@teemingc
teemingc deleted the adapter-vite-function branch September 1, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adapters - general Support for functionality general to all adapters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants