Is there any standard way to use Scala.js application as a libriary in CommonJS environment? And if not, can I patch generated js file for that purpose?
Asked
Active
Viewed 785 times
1 Answers
11
Scala.js 0.6.13 and onward
Put this in your build file:
scalaJSModuleKind := ModuleKind.CommonJSModule
Scala.js 0.6.5 to 0.6.12
Put this in your build file (explanation see below):
scalaJSOutputWrapper := ("var __ScalaJSEnv = { exportsNamespace: exports };", "")
Scala.js 0.5.4 to 0.6.4
You can tell Scala.js where to send the stuff it exports. To make a CommonJS module, simply prepend this:
var __ScalaJSEnv = {
exportsNamespace: exports
};
to the .js
file produced by fastOptJS
/fullOptJS
.
Pre Scala.js 0.5.4
Please upgrade :)

gzm0
- 14,752
- 1
- 36
- 64
-
2As of Scala.js 0.6.5, this can be automated with a single line of sbt configuration: `scalaJSOutputWrapper := ("var __ScalaJSEnv = { exportsNamespace: exports };", "")`. It will be include in the `-fastopt.js` and `-opt.js` files. – sjrd Aug 31 '15 at 08:13