Minimal example making webpack and wasm/Emscripten work together.
Build instructions:
- Clone this gist
npm install
npm start
- Open
http://localhost:8080
- Look at console
Note: Docker is required to build this project.
I filed a bug with webpack to make this integration easier.
More questions? Hit me up on Twitter.
License Apache-2.0
<3 Surma
This original gist helped me years ago, but it stopped working (for me...). Some advices that worked here:
package.json
:"build:codec": "docker run --rm -v $(pwd):/src emscripten/emsdk emcc -O3 -s WASM=1 -s EXPORTED_RUNTIME_METHODS='[\"cwrap\"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"fibonacci\"' -o ./fibonacci.js fibonacci.c"
emcc: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
trzeci/emscripten
seems to be officially replaced byemscripten/emsdk
devDependencies
because some packages were old, specially http-server (webpack is still v4 and couldn't manage to make it work on v5):webpack.config.js
:library
tomodule.exports.output
:library: 'TestLib'
index.js
:onRuntimeInitialized
as in the original exampleindex.js
On the browser,
TestLib.loadedModule._fib(5)
correctly invokes the function fib.index.html
webpack.config.js
packages.json:
fibbonacci.c (original file)