how to correctly import js script from wasm rust

Viewed 151

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?

0 Answers
Related