#Bundler not copying assets

1 messages · Page 1 of 1 (latest)

warm garden
#

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?

#

I'm not getting any errors from the build process, but here's a sample of what it looks like:

$ bun run build.js
{
  outputs: [
    BuildArtifact (entry-point) {
      path: "/Users/NAMEHERE/src/automaton/web/dist/main.js",
      loader: "ts",
      kind: "entry-point",
      hash: "56333952662201fd",
      FileRef ("/Users/NAMEHERE/src/automaton/web/dist/main.js") {
        type: "text/javascript;charset=utf-8"
      },
      sourcemap: null
    }
  ],
  success: true,
  logs: [
    12 |     "./snippets/*"
         ^
warn: wildcard sideEffects are not supported yet, which means this package will be deoptimized
   at /Users/NAMEHERE/src/automaton/web/pkg/package.json:12:5
  ],
}
Outputted:  [
  BuildArtifact (entry-point) {
    path: "/Users/NAMEHERE/src/automaton/web/dist/main.js",
    loader: "ts",
    kind: "entry-point",
    hash: "56333952662201fd",
    FileRef ("/Users/NAMEHERE/src/automaton/web/dist/main.js") {
      type: "text/javascript;charset=utf-8"
    },
    sourcemap: null
  }
]
0
#

Oh and when I try running the bundled JS with bun itself I get this:

bun run dist/main.js
ENOENT: No such file or directory
   errno: -2
 syscall: "open"
   path: "/Users/NAMEHERE/src/automaton/web/dist/automaton_bg.wasm"
shrewd sage
#

I'm having the same issue, did you figure this out?