How do I port an existing Scala library to scalajs?

别说谁变了你拦得住时间么 提交于 2019-12-03 17:11:41

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30143126/how-do-i-port-an-existing-scala-library-to-scalajs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!