fix(cloudflare-rolldown-plugin): inline wasm/bin/text content in dev SSR#847
Closed
Cyberistic wants to merge 1 commit into
Closed
fix(cloudflare-rolldown-plugin): inline wasm/bin/text content in dev SSR#847Cyberistic wants to merge 1 commit into
Cyberistic wants to merge 1 commit into
Conversation
Cyberistic
marked this pull request as draft
July 16, 2026 21:21
The `additional-modules` plugin rewrites `import 'foo.wasm'` (and .bin, .txt, .html, .sql) to a virtual `__CLOUDFLARE_MODULE__CompiledWasm__/<abs> __CLOUDFLARE_MODULE__` URL so the bundler can inline the file's content as an asset at build time. In dev (no `renderChunk`), Vite's Node-side SSR module runner still resolves that virtual ID and then tries to load it. The 'file' portion is just a marker — vite's `transformRequest` runs, finds no real file on disk, and throws `Failed to load url __CLOUDFLARE_MODULE__...`. Fix: add a `load` hook that matches the virtual id, reads the .on-disk .wasm / .bin / .txt file here in the plugin (Vite Node main process), and inlines the bytes as a base64 string literal in the returned module source. Why base64: Vite evaluates the returned source inside `new AsyncFunction(...)`, where top-level `import` statements are illegal. The returned source has no imports — it builds the buffer from the inlined string with `Buffer.from(__b64, 'base64')`. Why CompiledWasm / Text / Data each get their own branch: `CompiledWasm` and `Data` should produce binary buffers; `Text` is utf-8 text. Each branch emits a default export of the correct shape for its consumer.
Cyberistic
force-pushed
the
fix/cloudflare-rolldown-plugin-ssr-load
branch
from
July 16, 2026 21:21
6d7f3c4 to
97c1893
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR CLOSED AND MOVED TO: alchemy-run/cloudflare-tools#67