code • #ifdef EMSCRIPTEN • keep both native and Emscripten pathways working • some issues can be debugged with native tools • also easier integration of upstream changes
scripts/environment variables • for meta build systems (autotools, cmake, etc), plumb your changes through to make, don’t modify output files (obvious, but…) • automate everything so you can keep iterations tight Image credit: James Halliday (@substack)
build out-of-tree, never clean, or, clean when switching between native and JS targets, but not when rebuilding • avoid packing data files – requires a rebuild every time data files change • have example program or tests for continuous feedback • optimisation level (-O flag) makes a big difference to perf • debug level (-g flag) disable some optimisations, -g4 creates source maps
lots of globals • you can wrap Emscripten's output in a function - with a prologue defining var Module, - and an epilogue to expose APIs you need (FS, PATH, etc)
an object called Module to be defined var Module = opts || {}; // hide node/commonjs globals so environment is not detected as node var process = null; var require = null; // [emscripten output goes here] // expose stuff which emscripten defines in this scope Module.FS = FS; Module.PATH = PATH; Module.IDBFS = IDBFS; Module.NODEFS = NODEFS; return Module; }