Chapter 21. Scala.js, GraalVM, and jpackage

The Scala.js project lets you write Scala code as a powerful, type-safe replacement for JavaScript. In short, when you need to write JavaScript, use Scala.js instead, and use sbt and the Scala.js plugin to compile your Scala.js code into JavaScript. Just like scalac compiles your code into .class files that work with the JVM, the Scala.js plugin compiles your Scala code into JavaScript code that runs in the browser.

The Scala.js website describes Scala.js as “a safer way to build robust front-end web applications.” With benefits like being able to use classes, modules, a strong type system, a huge collection of libraries, and IDE support for easy refactoring, code completion, and much more, Scala.js is a strong alternative to JavaScript and other JavaScript replacements like CoffeeScript, Dart, and TypeScript. Scala.js lets you use the same tools you use for server-side development to write client-side code.

The benefits of Scala.js compared to other browser technologies are summarized in Figure 21-1, which is reproduced here courtesy of the Scala.js website.

This chapter includes three Scala.js recipes to help you get started:

  • Recipe 21.1 demonstrates how to get the Scala.js environment up and running.

  • With your environment set up, Recipe 21.2 shows how to write Scala/Scala.js code to respond to events like button clicks.

  • Recipe 21.3 then shows how to get started writing single-page web applications.

Figure 21-1. The advantages ...

Get Scala Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.