Skip to content

Comments

Build modularized JS toolkit with support for -s EXPORT_ES6#3174

Merged
lpugin merged 5 commits intorism-digital:developfrom
WolfgangDrescher:export-es6
Dec 22, 2022
Merged

Build modularized JS toolkit with support for -s EXPORT_ES6#3174
lpugin merged 5 commits intorism-digital:developfrom
WolfgangDrescher:export-es6

Conversation

@WolfgangDrescher
Copy link
Contributor

Related to #3168.

Recently there was some progress in emscripten to support ECMAScript modules and emscripten-core/emscripten#11792 was implemented in emscripten-core/emscripten#17915. This means that since em++ v3.1.27 we can use the EXPORT_ES6 flag to generate an ESM build of the emscripten module instead of a CommonJS module (that can be imported with ESM).

Is there anything I can add to force usage of em++ v3.1.27?

I did some tests an even without 3bca155 everything did work just fine in my project. But adding mjs as file extension will probably be the safer method to ensure the verovio-module will be used with ESM. For other usage you can still use verovio-toolkit-wasm.js with CommonJS due to the UMD format.

Probably this won't fix all cases when using verovio with bundlers (see this comment emscripten-core/emscripten#11792 (comment)) but it should still improve ESM support.

@lpugin
Copy link
Contributor

lpugin commented Dec 21, 2022

Thanks!

Is there anything I can add to force usage of em++ v3.1.27?

Could you try to add this to the cmake file (in elseif (BUILD_AS_WASM):

    if (EMSCRIPTEN_VERSION VERSION_LESS "3.1.27")
        message(FATAL_ERROR "You need em++ 3.1.27 or greater")
    endif()

@WolfgangDrescher
Copy link
Contributor Author

Thanks, I added your snippet into CMakeLists.txt.

Additionally I improved error handling in buildToolkit (die when system($cmakeCmd) fails) and buildNpmPackage (script will stop at the first fatal error). Without this buildToolkit would still compile and link something but display red messages and buildNpmPackage would still build a corrupted toolkit and bundle something with npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants