I'm not really sure why, but for some reason the bundler doesn't seem to be copying a WASM file over to the bundle location despite changing the import paths to it.
This wasm file is generated alongside a bunch of JS and definitions using wasm-pack built from rust, and I'm keeping it all in a folder called pkg. The directory structure is as follows:
|--dist
| |-main.js
| |-WASM SHOULD BE COPIED HERE BUT ISN'T!
|--pkg
| |-automaton.d.ts
| |-automaton.js
| |-automaton_bg.wasm
| |-automaton_bg.wasm.d.ts
| |-package.json (Auto-created by wasm-pack to make it publishable)
|--src
| |-main.ts (Entrypoint)
|-build.js
|-index.html
|-package.json (Actual package.json)
Here is my main.ts, a pretty simple thing for a toy project I'm building:
import init, { WebRegex } from "../pkg/automaton"
function main() {
const regex = new WebRegex(".* off");
if (regex.accepts("Piss off")) {
console.log("I don't think I will");
} else {
console.log("Something has gone horribly wrong");
}
}
init().then(main);
Here is the build.js:
const res = await Bun.build({
entrypoints: ['./src/main.ts'],
outdir: './dist'
});
console.log(res);
console.log("Outputted: ", res.outputs)
for (const message in res.logs) {
console.log(message);
}
For whatever reason, this is not copying over the WASM, but it is renaming a path that references the WASM, as I get the following error in my browser:
Failed to load resource: the server responded with a status of 404 (File not found) http://localhost:8000/dist/automaton_bg.wasm
When I manually copy over the file to dist, it all just works.
Am I missing something here? Why isn't bun copying this file with the bundling process when it clearly knows it should?