[wrangler] Fix autoconfig for Vite projects without a config file#14074
Conversation
Vite projects scaffolded without a vite.config file (e.g. create-vite vanilla, react-swc, lit templates) failed with 'Could not find Vite config file to modify'. When no config file exists, autoconfig now generates a minimal one with the Cloudflare plugin already wired in. The Vite.isConfigured() method also returns false instead of throwing in this case. The fix is scoped to the Vite framework class. Other frameworks that use the shared vite-config utilities (React Router, TanStack) still get the existing throw behaviour, which is correct for them.
🦋 Changeset detectedLatest commit: fbac515 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
|
React Router and TanStack both call Now I have a thorough understanding. Let me check one more thing — the changeset file references only Let me look at one potential issue more carefully — the In the dry-run test (line 89-105), However, I notice one thing: the test at line 89 does NOT mock I'm satisfied with my review. The code changes are clean, correct, and well-scoped. The logic is sound:
LGTM |
|
✅ All changesets look good |
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
dario-piotrowicz
left a comment
There was a problem hiding this comment.
LGTM
I also prefer this simpler PR for fixing this compared to #14073 (which is anyways still in draft)
I think that anyways some aspects of 14073 are however good and should be still included (as a followup) such as checking whether the vite config file is cjs.
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
wrangler setupcrashed with "Could not find Vite config file to modify" for Vite projects that have novite.config.jsorvite.config.ts. Vite does not require a config file for simple projects, so severalcreate-vitetemplates omit it entirely.When no config file exists, autoconfig now creates a minimal one with the Cloudflare plugin already configured.
isConfigured()also returnsfalseinstead of throwing.The fix is scoped to the
Viteframework class only. Other frameworks that use the sharedtransformViteConfigutility (React Router, TanStack) are unaffected -- they always have a config file, and the existing throw behaviour is correct for them.Affected templates (6 of 16):
vanilla,vanilla-ts,react-swc,react-swc-ts,lit,lit-tsKnown issue:
create-vite --template soliddetected as Static instead of Vite@netlify/build-infocorrectly identifies plain Solid projects assolid-js(distinct fromsolid-start). However, wrangler'sallKnownFrameworkslist hassolid-startbut notsolid-js, sogetFrameworkClassInstancefalls back to theStatichandler. This means plain Solid SPAs getassets.directorywithoutnot_found_handling: "single-page-application", which would cause 404s on client-side routes.This is a separate issue from the config file fix in this PR. A follow-up could add fallback logic in the autoconfig layer: when an unknown framework is detected but the project has
viteas a dependency and usesvite build, route it through theVitehandler instead ofStatic.