Sparrow10

Ideas, drafts, and hacks

07 Aug 2022

How to start a Scala.js project

Scala.js is a Scala to JavaScript compiler. In this post, we are going to see a couple of ways to start a project. Foremost we need to install sbt and node.js (I prefer to use nvm which allows us to install and use different versions).

One way to start a project in Scala is using a giter8 template. For Scala.js there is no template from official sources, but some were created by third parties. These templates create projects for Scala.js and add libraries to help to build your application more easily.

For example if you wan’t to create a project with Scala.js and Akka HTTP you can use giter8 from sbt on the command line by typing:

And you are set to start coding your application.

screenshot of

Another option to start a project with Scala.js is following the steps from the documentation to set up a project. In this case, you can add this compilation option to a new project or just start on a clean slate. For that we start with a new project, we can use a seed giter8 project.

Now we add the Scala.js sbt plugin in project/plugins.sbt

And enable this plugin on the build.sbt file of the project.

Last, we need to specify the sbt version in project/build.properties.

To get your stack traces resolved on node.js, you will have to install the source-map-support package.

And now lets add some code in src/main/scala/example/Hello.scala to test our configuration.

And now we can run the projec typing: sbt run

See you next time to integrate HTML to thie newly created project.