feat: allow adapters to pass a function for vite config - #16986
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/0c1556ea1e5fb00cff14e219af3f0bbdb84a02eeOpen in |
🦋 Changeset detectedLatest commit: 0c1556e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
| * 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[]; | ||
| }; |
There was a problem hiding this comment.
I feel a little conflicted about having the single array option default to pre. I kind of liked the explicitness of pre and post.
There was a problem hiding this comment.
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.
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughSvelteKit 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. ChangesAdapter Vite configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation 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
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Comment |
For adapter-cloudflare, we need to add
@cloudflare/vite-pluginto thevite.pluginsarray. However, while configuring the plugin, we need access tosvelte_config.out_dirin order to tell it how to generate thewranglerconfig.This plugin allows adapters to do
Drive-by, also allows adapters to just specify a
pluginsarray if they don't need to specifypreandpost. This is backwards-compatible.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Summary by CodeRabbit