Florian Baierl
Florian Baierl

Reputation: 2491

Making a JVM scala library available in Scala.js

What is the standard/easiest way to make a normal scala library (sbt) available for scala.js (also sbt)? Do I just copy/fork the source files into a scala.js project and build that or is there any smart way to 'wrap' a JVM Scala library and make it usable in a scala.js application?

I am asking because there is an open-source library for JVM scala that I want to use in a scala.js application. I have already copied the .scala files and modified them a bit and everything works fine for now, but this approach seems a bit too 'straight-forward'/clumsy.

Upvotes: 3

Views: 193

Answers (1)

Justin du Coeur
Justin du Coeur

Reputation: 2659

You want to turn it into a cross-building library. See this page for details, but the summary is that you typically create a "shared" code directory for code that is identical on both sides, with JVM and JS directories for bits that are specific to one platform or the other. Or you can create a "pure" cross-project, which simply compiles both ways.

Note that this assumes that you have control of the library, though. I don't know of any way to "wrap" somebody else's library without their assistance -- in that case, I would probably fork the library and turn the fork into a cross-building one.

Upvotes: 4

Related Questions