Chapter 12Scala.js
Scala.js is a relatively new feature in Scala that allows you to compile Scala code straight to JavaScript, providing you with the full power of the Scala language, while being able to target JavaScript. It also allows you to share code between the server and the client, which can dramatically reduce boilerplate, especially if you use one of the many pickling/serialization libraries available in Scala.
This chapter also covers Webjars, which are Maven packages with installed resources. Using Webjars, plus the powerful interoperability features that Scala.js provides, provides you with a compelling and fresh way to tackle the highly complex area of web programming.
SCALA.JS AND ITS DESIGN
Scala.js, foremost, is a Scala compiler. That is, it takes .scala files, and compiles them to an intermediate bytecode specifically designed for JavaScript (.sjsir) files. When combined with .sbt, you can then produce an actual .js file.
This means that Scala.js does not work with Java source code, nor does it work with JVM bytecode. This means that when using Scala.js, you must use pure Scala code and any dependencies that you may have also have to be written in pure Scala. For this reason, you may have difficulties in using Scala.js in a project that heavily uses Java (either directly or indirectly). Strong integration with Scala.js and SBT means that it's ...
Get Professional Scala 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.