简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM