Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bundle / specify wasm URL? #13

Closed
phiresky opened this issue May 15, 2021 · 3 comments
Closed

How to bundle / specify wasm URL? #13

phiresky opened this issue May 15, 2021 · 3 comments

Comments

@phiresky
Copy link

Using webpack, it tries to load the WASM from a file:/// url and the wasm file is not bundled as an asset. Is it possible to specify the wasm URL or make it work with webpack in some other way?

@phiresky
Copy link
Author

it would work correctly if you get the URL by doing

const url = new URL('./foobar.wasm', import.meta.url).toString()

@rhashimoto
Copy link
Owner

I've never used Webpack and have no idea how it works. You can specify the WASM URL by passing an argument to the module factory, e.g.:

import SQLiteESMFactory from '../dist/wa-sqlite.mjs';
...
const module = await SQLiteESMFactory({
  locateFile(file) {
    return `https://rhashimoto.github.io/wa-sqlite/dist/${file}`;
  }
});

...but I don't know whether Webpack would pick that up.

Because I don't know Webpack, I don't understand your second comment - is that something you're suggesting as a user workaround, or for me to put in the package somewhere?

Is the Emscripten ES6 modularization part of the problem? Building a CommonJS module is just a matter of changing .mjs to .js in the Makefile. I can build both if that's easier to use with Webpack.

Sorry, but Webpack is not even a black box to me; I don't even know what the box looks like! 😀

@phiresky
Copy link
Author

phiresky commented May 16, 2021

Is the Emscripten ES6 modularization part of the problem?

No, webpack works fine with ES6.

I don't understand your second comment - is that something you're suggesting as a user workaround, or for me to put in the package somewhere?

If you use that code snippet within the library to get the wasm file path, then webpack will realize the wasm file is an asset that needs to be written to the output folder. But looking at the code, I see that the wa-sqlite.mjs code is completely generated by emscripten so I guess you don't actually have control over that, it needs to be "fixed" on their side.

Your locateFile solution works though, thanks. You should maybe add the info to the readme since I'd guess most people use a bundler / webpack.

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

No branches or pull requests

2 participants