A somewhat advanced template for a Scala.js project targeting Web, MacOS, Windows and Linux.
Based on Scala.js Project Template, see details there.
The project shows common stuff one implements in a real-world crossplatform app for Web and Desktop.
- The project produces
- Web files,
- Exe setup file for Windows,
- Zip and Dmg files for MacOS,
- AppImage file for Linux,
- YML files for auto-updating.
- Uses Electron Builder.
- Uses auto-update mechanism (see
/resources/templates/electron_main.js
). - Uses event-based communication between main desktop process and web app inside.
- Uses application system badge (normally used to show update count).
- Shows accessing Electron-specific services from web app.
- Prevents desktop app from closing until web app reports it is ready to close.
Build target folder is bin
in project root. That's where all of the resources are copied and where the fastOptJs
/fullOptJS
output is directed.
The version
build parameter is optional, it defaults to the version
setting in build.sbt
.
/build-web-dev.sh -Dversion="0.1.0"
or
/build-web-release.sh -Dversion="0.1.0"
Open /bin/web/index.html
to see the result.
/build-electron-dev.sh -Dversion="0.1.0"
or
/build-electron-release.sh -Dversion="0.1.0"
Open /bin/electron/dist/
to see the results for all platforms.
Start SBT with sbt -mem 2000 -Dversion="0.1.0"
. The memory setting here prevents SBT from crashing with out of memory exception after a dozen rebuilds in interactive mode.
- Use
release
ordev
commands to clean, build and collect resources. - Use
webRelease
orwebDev
to build and collect resources. - Use
fastOptJS
orfullOptJS
as you normally would with any Scala.js project to just build main javascript files.
- Use
electronMac
,electronWin
,electronLinux
to clean & build release version of Web and Electron app for a platform. - Use
electron mac
,electron win
,electron linux
to build Electron app using current web build. This way you can use fast-optimized JavaScript in Electron build. This will fail if you don't build for web beforehand.
/bin
– this is where all build files go. The directory is created by build commands and is deleted completely byclean
command./bin/web
– Web build./bin/electron/dist
– Electron build./project
– a standard SBT project directory, which containsBuildUtils.scala
, that does file manipulation during build and launches Electron build./resources
– contains static resources (like css and images) and templates (html, js, json) that get processed by build logic./src/main/resources/
– the standard directory for js libraries. Seejs/example.js
there.