Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Scala.js application to CommonJS module?

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?

like image 681
AIring Avatar asked Oct 29 '14 18:10

AIring


1 Answers

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 :)

like image 106
gzm0 Avatar answered Oct 28 '22 19:10

gzm0