2

How do you let webpack know that a chunk is used inside of rust/wasm so that it doesn't get discarded.

My try: webpack config:

module.exports: {
...
entry:  {
        main: './index.js',
        worker: './worker.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist'),
    },

}

rust [wasm_bindgen]:

#[wasm_bindgen]
pub async fn start() -> Result<(), JsValue> {
    let worker = Worker::new("/worker.js")
}

Plus, if I'm using wasm inside of the worker.js script as well, how would I go about importing it without the .wasm chunk getting dropped too?

Mattia
  • 179
  • 15
  • 1
    I'm not super familiar with webpack, but you may be able to specify that the file has [side effects](https://webpack.js.org/guides/tree-shaking/) to avoid discarding it. Not sure if there's a better way though. – kmdreko Jun 12 '21 at 22:42
  • If you're trying to use threads, you might want to check out https://github.com/GoogleChromeLabs/wasm-bindgen-rayon which provides Rayon + wasm-bindgen integration and already took care to solve those bundler integration issues. – RReverser Jun 13 '21 at 02:03

0 Answers0