Skip to content

Commit

Permalink
chore(rollup): Externalize all imports that end with .wasm?module (#…
Browse files Browse the repository at this point in the history
…217)

This change externalizes any file we import that ends in `.wasm?module` and links to the cloudflare worker documentation. This is a cleaner solution than what existed once we start adding more wasm modules, such as [Rate Limit](#205).
  • Loading branch information
blaine-arcjet authored Feb 9, 2024
1 parent 402c2ad commit ee6f387
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 0 additions & 6 deletions analyze/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ export default createConfig(import.meta.url, {
external: true,
};
}
if (source === "./wasm/arcjet_analyze_js_req_bg.wasm?module") {
return {
id: "./wasm/arcjet_analyze_js_req_bg.wasm?module",
external: true,
};
}
// TODO: Generation of this file can be handled via rollup plugin so we
// wouldn't need to externalize here
if (source === "./wasm/arcjet.wasm.js") {
Expand Down
13 changes: 13 additions & 0 deletions rollup-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ export function createConfig(root, { plugins = [] } = {}) {
include: "test/*.ts",
noEmitOnError: true,
}),
{
name: "externalize-edge-wasm",
resolveId(id) {
// Cloudflare uses the `.wasm?module` suffix to make WebAssembly
// available in their Workers product. This is documented at
// https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#bundling
// Next.js supports the same syntax, but it is undocumented.
if (id.endsWith(".wasm?module")) {
return { id, external: true };
}
return null;
},
},
...plugins,
],
};
Expand Down

0 comments on commit ee6f387

Please sign in to comment.