diff --git a/js/dune b/js/dune index f4f9d5fd..b11add45 100644 --- a/js/dune +++ b/js/dune @@ -10,4 +10,4 @@ (names stubs)) (js_of_ocaml (flags --no-sourcemap) - (javascript_files binaryen.es5.js postlude.js))) + (javascript_files prelude.js binaryen.es5.js postlude.js))) diff --git a/js/postlude.js b/js/postlude.js index c44ccc5f..23fc50fc 100644 --- a/js/postlude.js +++ b/js/postlude.js @@ -1,2 +1,2 @@ -// Attach binaryen to our global -global.binaryen = module.exports; +// Attach binaryen to globalThis because JSOO wraps in an iife +globalThis.binaryen = module.exports; diff --git a/js/prelude.js b/js/prelude.js new file mode 100644 index 00000000..bf2be20c --- /dev/null +++ b/js/prelude.js @@ -0,0 +1,11 @@ +if (typeof module === 'undefined') { + module = {}; +} + +if (typeof exports === 'undefined') { + exports = {}; +} + +if (typeof module.exports === 'undefined') { + module.exports = exports; +}