Allow loaders to emit wasm

Feature request

What is the expected behavior?

Loader can emit wasm

What is motivation or use case for adding/changing the behavior?

WebAssembly is just a compilation target and can be abstracted away from the user.

They should be able to write C, rust, etc and interact with JavaScript. Some loaders already offer a similar experience but Webpack restrict their usage.

How should this be implemented in your opinion?

A loader can already ask for an ArrayBuffer but still need to emit JavaScript. I would suggest to allow an ArrayBuffer in emit since wasm has a magic header and can reliably be detected.

In the future we could even concat all wasm modules together or treeshake them. Webpack will basically act as a linker.

Are you willing to work on this yourself?
yes

Author: Fantashit

1 thought on “Allow loaders to emit wasm

  1. Loaders can return wasm. You just have to add type: "webassembly/experimental" to the rule.

    i. e.

    module.rules: [{
      test: /\.c$/,
      loader: "compile-c-to-wasm-loader",
      type: "webassembly/experimental"
    }]

Comments are closed.