diff options
Diffstat (limited to 'packages/integrations/cloudflare/src/utils/rewriteWasmImportPath.ts')
-rw-r--r-- | packages/integrations/cloudflare/src/utils/rewriteWasmImportPath.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/src/utils/rewriteWasmImportPath.ts b/packages/integrations/cloudflare/src/utils/rewriteWasmImportPath.ts new file mode 100644 index 000000000..ada19bb56 --- /dev/null +++ b/packages/integrations/cloudflare/src/utils/rewriteWasmImportPath.ts @@ -0,0 +1,29 @@ +import esbuild from 'esbuild'; +import { basename } from 'node:path'; + +/** + * + * @param relativePathToAssets - relative path from the final location for the current esbuild output bundle, to the assets directory. + */ +export function rewriteWasmImportPath({ + relativePathToAssets, +}: { + relativePathToAssets: string; +}): esbuild.Plugin { + return { + name: 'wasm-loader', + setup(build) { + build.onResolve({ filter: /.*\.wasm.mjs$/ }, (args) => { + const updatedPath = [ + relativePathToAssets.replaceAll('\\', '/'), + basename(args.path).replace(/\.mjs$/, ''), + ].join('/'); + + return { + path: updatedPath, + external: true, // mark it as external in the bundle + }; + }); + }, + }; +} |