How to convert a Scala.js application to a CommonJS module?

Is there any standard way to use the Scala.js application as libriary in CommonJS? And if not, can I fix the generated js file for this purpose?

+6
source share
1 answer

Scala.js 0.6.13 onwards

Put this in your build file:

scalaJSModuleKind := ModuleKind.CommonJSModule 

Scala.js 0.6.5-0.6.12

Put this in your build file (explanation below):

 scalaJSOutputWrapper := ("var __ScalaJSEnv = { exportsNamespace: exports };", "") 

Scala.js 0.5.4 to 0.6.4

You can tell Scala.js where to send the exported material. To create a CommonJS module, simply add this:

 var __ScalaJSEnv = { exportsNamespace: exports }; 

to the .js file created by fastOptJS / fullOptJS .

Pre Scala.js 0.5.4

Please update :)

+11
source

Source: https://habr.com/ru/post/977431/


All Articles