Skip to content

fix(deploy): bundle framework Workers with Cloudflare module rules and Worker conditions - #540

Open
Pleasurecruise wants to merge 1 commit into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-bundle
Open

Pleasurecruise wants to merge 1 commit into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-bundle

Conversation

@Pleasurecruise

Copy link
Copy Markdown

Fixes #539

prepareBundledBuildOutput bundles framework Worker output again with a plain Vite lib build. It now matches @cloudflare/vite-plugin in two ways:

  • Additional modules. A plugin applies the Cloudflare Vite plugin's module rules: .wasm and .wasm?module, .bin, .txt, .html and .sql, including # subpath imports that resolve to them. Matching imports stay external, and each file is emitted beside the bundle with a path relative to the chunk that imports it. copyBundle already uploads these files as wasm, data and text modules. The Cloudflare plugin does not export its rules, so the plugin repeats them.
  • Resolve conditions. The build uses WORKER_CONDITIONS, which Void's other Worker bundles already use. The constant moves from wrapper.ts to its own module so that cf-build-output.ts still loads Vite lazily.

Both changes apply to every bundle that prepareBundledBuildOutput builds, including the static Worker.

Tests

packages/void/test/unit/cf-build-output.test.ts:

  • A framework Worker with wasm-bindgen-style and plain Wasm, text and data imports, a # subpath import and a dynamic import produces wasm, text and data modules and passes the cf dry run.
  • A dependency with workerd and browser exports resolves to its workerd build.

Each test fails when its change is removed. vp run test, vp run --filter ./packages/void typecheck, vp lint and vp fmt --check pass.

I also prepared the output of a SvelteKit app that uses @resvg/resvg-wasm and micromark: index_bg.wasm is uploaded as a wasm module, and the bundle contains the Worker build of decode-named-character-reference.

…d Worker conditions

The framework Worker bundle now keeps Wasm, data and text imports as Worker
modules, as the Cloudflare Vite plugin does, and resolves dependencies with
Worker conditions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native deploy mishandles Wasm, text and data imports and package exports in framework Workers

1 participant