10. One Codebase, Three Runtimes
Coming soon
This chapter is an outline. The full draft ships in a follow-up PR.
What this chapter will cover
Scala 3 can target the JVM, JavaScript (via Scala.js), and native binaries (via Scala Native). Uni is designed so that a single piece of business logic compiles to all three. This chapter takes a working JVM service and shows the minimum changes needed to also ship it as a browser app and as a native binary.
Concepts introduced:
sbt-crossproject: onebuild.sbt, three platforms.- The
.jvm,.js, and.nativesource folders and what belongs in each. - Platform abstractions Uni gives you (HTTP, filesystem, timers) so your code stays identical.
- Things you cannot share: JVM-only file paths, browser-only DOM access, native-only syscalls — and how to isolate them.
- Building and distributing: a fat JAR, an optimized JS bundle, and a stripped native binary.
