Add per-Worker devOnly property to the plugin config#13985
Conversation
🦋 Changeset detectedLatest commit: 2dfbb39 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 |
|
✅ All changesets look good |
|
I'm Bonk, and I've done a quick review of your PR. This PR adds a Issue found:
|
create-cloudflare
@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: |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
| fs.writeFileSync( | ||
| path.resolve( | ||
| builder.config.root, | ||
| clientEnvironment.config.build.outDir, | ||
| "wrangler.json" | ||
| ), | ||
| JSON.stringify(outputConfig) | ||
| ); |
There was a problem hiding this comment.
🟡 Missing directory creation before writing wrangler.json for devOnly entry worker
In config.ts's buildApp handler, when the entry worker is devOnly (not built), the code writes wrangler.json directly to the client output directory using fs.writeFileSync without first ensuring the directory exists. The client output directory is only created by Vite when the client environment is actually built. In build.ts:50-60, createBuildApp only builds the client if hasClientEntry, getHasPublicAssets, or prerenderWorkerEnvironmentName is truthy. If none of these conditions hold (e.g., a devOnly entry worker with no index.html, no public assets, and no prerender worker), the client directory won't exist and fs.writeFileSync will throw an ENOENT error.
| fs.writeFileSync( | |
| path.resolve( | |
| builder.config.root, | |
| clientEnvironment.config.build.outDir, | |
| "wrangler.json" | |
| ), | |
| JSON.stringify(outputConfig) | |
| ); | |
| const wranglerJsonPath = path.resolve( | |
| builder.config.root, | |
| clientEnvironment.config.build.outDir, | |
| "wrangler.json" | |
| ); | |
| fs.mkdirSync(path.dirname(wranglerJsonPath), { recursive: true }); | |
| fs.writeFileSync(wranglerJsonPath, JSON.stringify(outputConfig)); |
Was this helpful? React with 👍 or 👎 to provide feedback.
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
| plugins: [ | ||
| cloudflare({ | ||
| auxiliaryWorkers: [ | ||
| { configPath: "./dev-only-worker/wrangler.jsonc", devOnly: true }, |
There was a problem hiding this comment.
Nit: Bike-shedding the name a bit as I find devOnly confusing 😄
How about build: false or skipBuild: true?
Replacement for #12788 that makes opting in explicit. This means it doesn't break compatibility with existing framework integrations.
Add per-Worker
devOnlyoption to the plugin configThis determines if the given Worker should be built. It accepts a
booleanor a function that returns aboolean. The function is evaluated lazily at build time, allowing frameworks to provide the value after initialization.Some frameworks, such as Astro, use the
ssrenvironment during development but omit it from the build if the app is fully static. In these cases, we now output an assets only version of the user's input Wrangler config to the output config in the client output directory.devOnlyoption to Vite plugin API reference cloudflare-docs#31016A picture of a cute animal (not mandatory, but encouraged)