3

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Are there any examples of such "pure" cross-projects which compile both ways? I am currently creating a (very) small library that has only one dependency (scalatest). Would something like this be usable for Scala.js out-of-the-box?
I don't have any pure examples myself; I'd probably recommend asking on the scala-js/scala-js Gitter channel. In principle, though, yeah -- once the project is published, it should be straightforwardly usable...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.