Scala Stack for Spring Boot 3, Scala 3. This project runs Spring Boot with 3 controllers:
- One responds with HTML created with ScalaTags
- One responds with CSS created with ScalaTags
- The last one creates a JavaScript with the Scala Stack JS Compiler by reading local ScalaJS source files
This means all web content is created by request, no static files. If you are running a development service you can change most content and then refresh the page to see the changes. Everything is also written in Scala which makes it easier to work with, can share logic and tests for instance.
This is a Spring Boot 3 Maven project that uses Open API, to create API routes and models, and the Scala Stack JS Compiler (external library) to compile ScalaJS source to JavaScript.
You need an external library to run this. It's public and available at Github.
- Clone https://github.com/aimmoth/scala-stack-js-compiler and build locally. It's an SBT project and you can use
> sbt publishM2
to build local Maven library. - Generate sources with Maven
> mvn generate-sources
- Package with Maven
> mvn clean package
You also need to copy the necessary libraries for the ScalaJS compilation. Copy the following libraries to the src/main/resources/libs folder:
- scala3-library_3-3.3.1.jar
- scala-library-2.13.10.jar
- scalajs-dom_sjs1_2.13-2.8.0.jar
- scalajs-javalib-1.12.0.jar
- scalajs-library_2.13-1.12.0.jar
Either use your IDE or Docker.
You can run as a Docker image with the provided Dockerfile.
- Build as instructed above
- Build image with docker
> docker build -t scala-stack-spring-boot-3/latest .
- Run
> docker run -p 8081:8080 scala-stack-spring-boot-3/latest
- Optionally you can mount volumes to your local files. This means you can edit and compile while server is running.
> docker run -p 8081:8080 -v ".\src\main\resources\static\scalajs:APP/src" -v ".\src\main\resources\libs:APP/libs" scala-stack-spring-boot-3/latest
It's not possible to use the Scala Stack JS Compiler in Windows. But you can run the project in Docker and link your local files. This means the docker images is running on one port 8081 and your local service run on 8080. When your page at 8080 needs the JavaScript, it will call the docker image, which compiles your local files.