Skip to content

Add assetsOnly/devOnly property to the plugin config - #13985

Merged
jamesopstad merged 6 commits into
mainfrom
james/dev-only-workers
May 26, 2026
Merged

Add assetsOnly/devOnly property to the plugin config#13985
jamesopstad merged 6 commits into
mainfrom
james/dev-only-workers

Conversation

@jamesopstad

@jamesopstad jamesopstad commented May 20, 2026

Copy link
Copy Markdown
Contributor

Replacement for #12788 that makes opting in explicit. This means it doesn't break compatibility with existing framework integrations.

Add assetsOnly (entry Worker) and devOnly (auxiliary Workers) options to the plugin config

Both options accept a boolean or a function that returns a boolean. The function is evaluated lazily at build time, allowing frameworks to provide the value after initialization.

Use assetsOnly on the entry Worker to skip building the Worker and instead emit an assets-only Wrangler config to the client output directory. This enables frameworks such as Astro to use the ssr environment during development but produce a fully static app for deployment.

export default defineConfig({
	plugins: [
		cloudflare({
			assetsOnly: () => isStaticBuild,
		}),
	],
});

Use devOnly on an auxiliary Worker to include it during vite dev but skip it at build time.

export default defineConfig({
	plugins: [
		cloudflare({
			auxiliaryWorkers: [
				{ configPath: "./dev-only-worker/wrangler.jsonc", devOnly: true },
			],
		}),
	],
});

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot

changeset-bot Bot commented May 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a690998

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

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 20, 2026
@jamesopstad jamesopstad added ci:c3-e2e Run C3 E2E tests on a pull request run-c3-frameworks-tests Run all the C3 frameworks tests on this PR labels May 20, 2026
@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

This PR adds a devOnly property to the vite-plugin-cloudflare config, allowing Workers to be excluded from production builds while remaining available during development. The implementation correctly handles filtering in buildApp, writeDeployConfig, and the output config plugin, with no double-write scenarios.

Issue found:

  1. Mislabeled describe block (prerendering.spec.ts:9): The describe block is labeled "no-ssr" but this is the default config where SSR is active (the test asserts status 200). The label was likely copy-pasted from no-ssr/prerendering.spec.ts. Posted a suggestion to rename it to "with-ssr".

github run

@pkg-pr-new

pkg-pr-new Bot commented May 20, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@13985

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@13985

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@13985

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@13985

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@13985

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@13985

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@13985

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vitest-pool-workers@13985

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-editor-shared@13985

@cloudflare/workers-utils

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-utils@13985

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@13985

commit: a690998

@jamesopstad
jamesopstad marked this pull request as ready for review May 22, 2026 08:00
@workers-devprod
workers-devprod requested review from a team and ascorbic and removed request for a team May 22, 2026 08:00
@workers-devprod

workers-devprod commented May 22, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@ascorbic ascorbic 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.

Nice!

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 22, 2026
Comment thread .changeset/rare-ducks-occur.md
@jamesopstad
jamesopstad marked this pull request as draft May 22, 2026 10:01
@jamesopstad
jamesopstad force-pushed the james/dev-only-workers branch from 2dfbb39 to 83a5849 Compare May 26, 2026 10:39
@jamesopstad
jamesopstad force-pushed the james/dev-only-workers branch from c020093 to d56338c Compare May 26, 2026 11:00
@jamesopstad
jamesopstad marked this pull request as ready for review May 26, 2026 11:24
@jamesopstad

Copy link
Copy Markdown
Contributor Author

@edmundhung I've renamed the option to assetsOnly on the entry Worker, which better reflects what it does.

Outputting the assets-only config and modified deploy config when the entry Worker is built would be breaking with the current setup, because in TanStack Start the modified deploy config would break pre-rendering. I plan to do a follow up PR once this one's released that doesn't read the deploy config during pre-rendering. Best to do that in a separate PR as it's a more risky change. Please take another look.

@jamesopstad
jamesopstad requested a review from edmundhung May 26, 2026 11:28

@edmundhung edmundhung left a comment

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.

It looks like you keep checking whether environment is built for now. Is that you plan to fix it all together with the prerendering issue you mentioned?

I am still unsure about the usecase of devOnly in auxiliary workers, but definitely not a blocking concern.

Feel free to merge :)

@jamesopstad jamesopstad changed the title Add per-Worker devOnly property to the plugin config Add assetsOnly/devOnly property to the plugin config May 26, 2026
@jamesopstad
jamesopstad merged commit c809d30 into main May 26, 2026
55 checks passed
@jamesopstad
jamesopstad deleted the james/dev-only-workers branch May 26, 2026 13:30
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:c3-e2e Run C3 E2E tests on a pull request run-c3-frameworks-tests Run all the C3 frameworks tests on this PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants