Scala.js example fullstack program
git clone https://github.com/oyvindberg/scalajs-workshop.git cd scalajs-workshop ./sbt dev
Look at Suggestions at the bottom
These are all examples of good micro-libraries that are cross-compiled for Scala.js
The Scala.js compiler has two modes:
Usage is just running either of those commands:
sbt> fastOptJS sbt> fullOptJS
bash> ls js/target/scala-2.12/scalajs-bundler/main 2,3M tutorial-fastopt-bundle.js <-- Result of bundling fastOptJS build with dependencies 2,7M tutorial-fastopt-bundle.js.map <-- Source map of bundle above 2,1M tutorial-fastopt.js <-- Result of fastOptJS 668K tutorial-opt-bundle.js <-- Result of bundling fullOptJS build with dependencies 876K tutorial-opt-bundle.js.map <-- Source map of bundle above 450K tutorial-opt.js <-- Result of fullOptJS
Since the project both has client and server code, we can reload one or both on code changes.
For the backend we use sbt-revolver. Usage is like this:
# start server sbt> tutorialJVM/reStart # restart server sbt> tutorialJVM/reStart # stop server sbt> tutorialJVM/reStop # status sbt> reStatus # continuously restart server on changed code sbt> ~tutorialJVM/reStart # alias sbt> devBack
# continuously compile and bundle code sbt> ~tutorialJS/fastOptJS::webpack # alias sbt> devFront
If you make changes both on client and server side, this snippet should do it:
# alias sbt> dev
Note that there is no synchronization between the two restarts, so
it's possible that the client will reload just as the server is restarting.
In that case, simply reload the browser, or use
Test code is transpiled and then executed on Node.js, which you need to install on your system if you want to run tests.
To run the frontend tests do this:
You can build a fatjar which is executable and will serve frontend contents as well:
sbt>tutorialJVM/assembly # [info] Packaging .../jvm/target/scala-2.12/tutorial-assembly-0.1.0-SNAPSHOT.jar ... shell> java -jar .../jvm/target/scala-2.12/tutorial-assembly-0.1.0-SNAPSHOT.jar
This repo was originally created for a workshop, and the idea was that people can play around. These are some suggestions for things that could be fun to play with:
Try to break it! The compiler generally has your back, and a lot of the pain points from traditional web development are gone, though some remain. By refactoring the application you can get a feeling for what is still brittle
Extend the application to show metadata. Last changed? file size? Right now it's pretty bare bones
Add support for showing content of files. Such basic functionality missing!. Can you make it happen?
Add support for several file browsers in tabs on the same page. Bootstrap has tabs, and the file browser just needs a DOM element to render to)
Add support for remembering state. The Local Storage API is defined in
dom.localStorage. You probably want to use uPickle for serialization
Breadcrumbs for the parent folders instead of the back button.
- Scala.js Gitter room Probably the best place for support
www.scala-js.org/ Tutorial, community, list of libraries, etc
Basic tutorial Tutorial on which this workshop was partly based
Hands-on Scala.js Comprehensive introductory material
TodoMVC example Frontend-only todo application with Scalajs-React