Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I port an existing Scala library to scalajs?

Tags:

scala.js

I'm new to Scala.js. I'd like to use the Argonaut json library.

https://github.com/argonaut-io/argonaut

Its only dependencies appear to be Monocle and Scalaz which both have versions compiled for Scala.js. I'd be happy to work on porting Argonaut to Scala.js, but don't have a firm idea on how to begin. Does anyone have any pointers?

Thanks.

like image 903
seanmcl Avatar asked May 09 '15 17:05

seanmcl


1 Answers

Quick proof-of-concept

The first thing to try is to convert the build so that the JVM projects become Scala.js projects. The basis for this is pretty easy:

In project/plugins.sbt, add the dependency to the Scala.js sbt plugin:

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.2")

In build.sbt or project/Build.scala (or similar, depending on what the given project uses), turn projects into Scala.js projects by adding:

.enablePlugins(ScalaJSPlugin)

to their definitions. For their dependencies, replace %% dependencies by %%% dependencies to depend on the Scala.js artifacts.

At this point, the code can be compiled, and can probably be used to write examples or to directly in your application. Complex builds can require more work.

If everything works fine in your application, then you've made a successful proof-of-concept that this library can be ported to Scala.js.

Going further: cross-compiling build

OK, so now that you have a quick proof-of-concept that the library can compile and work on Scala.js, you'll want to make a proper cross-compiling build instead of the quick fork. Indeed, now the build does not produce JVM artifacts anymore.

For this, you will need to re-transform all projects that need to cross-compiled into crossProjects. For this, I recommend the cross-building documentation page as a source for further documentation.

like image 114
sjrd Avatar answered Oct 17 '22 10:10

sjrd