Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add ES modules support #312

Conversation

vhiairrassary
Copy link
Contributor

@vhiairrassary vhiairrassary commented Aug 19, 2019

Fixes #293

Allow to use ES modules as well as CommonJS module.

WIP: BundlingMode.LibraryOnly() does not work yet as with:

<script src="[name]-fastopt-library.js"></script>
<script src="[name]-fastopt-loader.js"></script>
<script src="[name]-fastopt.js"></script>

the browser will not recognize the import syntax in the last script.

Adding the attribute type="module" is not enough: if [name]-fastopt.js contains something like import * as $i_jquery from "jquery"; then the following error is thrown:

Uncaught TypeError: Failed to resolve module specifier "jquery". Relative references must start with either "/", "./", or "../".

@julienrf
Copy link
Contributor

BundlingMode.LibraryOnly() does not work

I’m not sure what we can do about that. By design, the LibraryOnly mode can only work with a module kind that is understood by web browsers. We could just document that the LibraryOnly mode only works with CommonJSModule.

@a1russell
Copy link

Any update on this?

@jeroentervoorde
Copy link

jeroentervoorde commented Apr 6, 2020

I updated the PR against current master. It seems to work fine except for this warning when trying to configure ES modules in fullOptJS ):

"The module kind in scalaJSLinkerConfig in (learnreact, compile, fullOptJS) is different than the one in (learnreact, compile)`. Some things will go wrong."

In build.sbt I used: scalaJSLinkerConfig in fullOptJS ~= (_.withModuleKind(ModuleKind.ESModule))

Not sure what to do about that. We should be able to configure ES modules in fullOptJS only i guess as it does not work will BundlingMode.LibraryOnly()

My reason to enable this is fullOptJS is the smaller bundler size. It generates a 25% smaller output file. Probably because of the better DCE for ES modules in webpack.

Updated PR.
#336

@vhiairrassary
Copy link
Contributor Author

Closing in favor of #336

@vhiairrassary vhiairrassary deleted the vhiairrassary/es-modules-support branch January 8, 2021 16:33
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.

Support ModuleKind.ESModule
4 participants