How do I port an existing Scala library to scalajs?

大憨熊 提交于 2019-12-03 05:29:36
sjrd

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.

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