By default, the
-fullopt.js files produced by Scala.js are top-level scripts, and their
@JSExported stuff are sent to the global scope.
Two kinds of modules are supported: CommonJS modules (traditional module system of Node.js) and ECMAScript modules. They are enabled with the following sbt settings:
Important: Using this setting is incompatible with the (deprecated) setting
persistLauncher := true.
It is also basically incompatible with
jsDependencies; use scalajs-bundler instead.
When emitting a module,
@JSExportTopLevels are really exported from the Scala.js module.
Moreover, you can use top-level
For example, consider the following definitions:
Once compiled under
ModuleKind.CommonJSModule, it would instead be equivalent to: