This is a Giter8 skeleton for ScalaJS. It can be launched with Electron or served with Express out-of-the-box. And launch configurations are pre-created for the Visual Studio Code editor. But, use of it is not required.
Download an install the following applications:
Next, run SBT on the command line to initialize a new sekeleton.
$ sbt new massung/scala-js-skeleton.g8 [-b webpack]
NOTE: If you'd like a skeleton that makes use of the ScalaJSBundler plugin and Webpack, then use the -b webpack
branch of the repository.
Once the skeleton has been created, cd
into it and install all the NodeJS dependencies with Yarn (or npm).
$ yarn install
Next, launch SBT and build the source for the skeleton.
sbt> fastOptJS
Note: if you are using the webpack branch, run fastOptJS::webpack
instead.
At this point, you application's compiled .js
file has been built and resides in the web/js
folder along with a .js.map
file and any other bundled, javascript dependencies.
To run your app, there are a few options:
If you are using VSCode, there are already launch configurations created for each: Run/Debug (Electron) and Serve (Express).
Otherwise, you can manually run/debug via the command line:
$ ./node_modules/.bin/electron main.js [debug]
If you pass the debug
argument on the command line, then the webkit debugger will be opened as well. From there, you should have access to your Scala code, as a map file was generated for it.
Or start the Express server:
$ node server.js [port=8080]
That's it!
Here is a high-level breakdown of the skeleton source files:
- project/ contains SBT plugins and settings
- src/ contains all the ScalaJS app code
- web/ contains all the static resources, and your app bundle
- main.js is the Electron application code
- server.js is the Express web server code
Everything in web/ will be exposed to your application at runtime. And the ScalaJS app will be compiled to JavaScript to web/js/ folder.