|
| 1 | +# All-in-One Scala.js Static Web Project Template |
| 2 | +[](https://gitpod.io/#https://github.com/Atry/scalajs-all-in-one-template) |
| 3 | +[](https://github.com/Atry/scalajs-all-in-one-template/actions/workflows/scala.yml) |
| 4 | + |
| 5 | +This repository is a template of the basic structure for a Scala.js web project, contains all the best technologies in Scala.js community until 2023: |
| 6 | + |
| 7 | +* [Sbt](https://scala-sbt.org) is the build tool. |
| 8 | +* [Scala.js](https://www.scala-js.org/) to compile [Scala](https://scala-lang.org) to JavaScript. |
| 9 | +* [html.scala](https://github.com/GlasslabGames/html.scala/) for reactive HTML templating. |
| 10 | +* [Binding.scala](https://github.com/ThoughtWorksInc/Binding.scala) for data-binding. |
| 11 | +* [sbt-sassify](https://github.com/irundaia/sbt-sassify/) for compiling [Sass](https://sass-lang.com/) to CSS. |
| 12 | +* [Font Awesome](https://fontawesome.com/) as an example of Sass dependency. |
| 13 | +* [Bootstrap](https://getbootstrap.com/) for responsive UI components. |
| 14 | +* [sbt-scala-js-map](https://github.com/ThoughtWorksInc/sbt-scala-js-map) for source mapping. |
| 15 | +* [scalajs-bundler](https://github.com/scalacenter/scalajs-bundler) for [webpack](https://webpack.js.org/) and [NPM](https://www.npmjs.com/) (or [YARN](https://yarnpkg.com)). |
| 16 | +* [ScalablyTyped](https://scalablytyped.org/) for type definition of NPM dependencies. |
| 17 | +* [pad](https://pad-project.js.org/) as an example of NPM dependency. |
| 18 | +* [sbt-web](https://github.com/sbt/sbt-web) for [WebJars](https://www.webjars.org/). |
| 19 | +* [sbt-buildinfo](https://github.com/sbt/sbt-buildinfo) to expose sbt settings to runtime. |
| 20 | +* [Coursier](https://get-coursier.io/) for fast downloading Maven and ivy dependencies. |
| 21 | +* [sbt-example](https://github.com/ThoughtWorksInc/sbt-example) to generate [ScalaTest](http://www.scalatest.org/) from from examples in Scaladoc comments. |
| 22 | +* [sbt-dynver](https://github.com/dwijnand/sbt-dynver) to determine the build version from git tags. |
| 23 | + |
| 24 | +Note that the default branch of this repository is written in Scala 3. Check out the [scala-2.13](https://github.com/Atry/scalajs-all-in-one-template/tree/scala-2.13) branch for a project template in Scala 2.13. |
| 25 | + |
| 26 | +Other libraries and tools can be found in [sbt settings](https://github.com/Atry/Binding.scala-template/search?q=extension%3Asbt&unscoped_q=extension%3Asbt). |
| 27 | + |
| 28 | +This template contains settings for a static web project, and you can additionally configure Play or Akka HTTP dependencies in `web/build.sbt` to turn it into a dynamic web project. |
| 29 | + |
| 30 | +## Directory Structure |
| 31 | + |
| 32 | + * web/ |
| 33 | + |
| 34 | + The sbt-web project for web assets |
| 35 | + * build.sbt |
| 36 | + |
| 37 | + Sbt settings for the sbt-web project, which contains WebJars dependency configurations, including SASS / SCSS dependencies and static resources from external libraries. |
| 38 | + * src/main/assets/ |
| 39 | + |
| 40 | + The root directory of static assets sources. |
| 41 | + * index.html |
| 42 | + |
| 43 | + The main page in release mode, which references uglified CSS and JS resources. |
| 44 | + * devMod.html |
| 45 | + |
| 46 | + The main page in development mode, which references indented CSS and JS resources. |
| 47 | + * style.scss |
| 48 | + |
| 49 | + The style sheet used by main page in SCSS syntax, which will be compiled to `style.css` by a sbt-web pipeline. |
| 50 | + * target/web/public/main/ |
| 51 | + |
| 52 | + The root directory of static assets output. |
| 53 | + * lib/ |
| 54 | + |
| 55 | + The output directory for Webjars dependencies. |
| 56 | + * js/ |
| 57 | + |
| 58 | + The Scala.js project to create JS output used in the sbt-web project. |
| 59 | + |
| 60 | + * build.sbt |
| 61 | + |
| 62 | + Sbt settings for the Scala.js project, which contains Scala.js settings, NPM dependencies and type definitions. |
| 63 | + |
| 64 | + * src/main/scala/ |
| 65 | + |
| 66 | + The directory contains Scala.js source files. |
| 67 | + * project/ |
| 68 | + * plugins.sbt |
| 69 | + |
| 70 | + Sbt plugins dependencies. |
| 71 | + |
| 72 | +## Requirements |
| 73 | + |
| 74 | +* [Java](https://openjdk.java.net/) 8+ |
| 75 | +* [Sbt](https://www.scala-sbt.org/) launcher |
| 76 | +* [Node.js](https://nodejs.org/) or [nodenv](https://github.com/nodenv/nodenv) |
| 77 | + |
| 78 | +## How to use this template? |
| 79 | + |
| 80 | +Just clone this repository, and the following sbt tasks are available. |
| 81 | + |
| 82 | +### Build |
| 83 | + |
| 84 | +Run the following command: |
| 85 | + |
| 86 | +``` shell |
| 87 | +sbt assets |
| 88 | +``` |
| 89 | + |
| 90 | +Then visit `web/target/web/public/main/devMod.html` to browse the main page. |
| 91 | + |
| 92 | +#### Release mode build |
| 93 | + |
| 94 | +By default, the `assets` command builds Scala.js in development mode. To build this project in release mode |
| 95 | + |
| 96 | +``` shell |
| 97 | +sbt "set scalaJSStage := FullOptStage" assets |
| 98 | +``` |
| 99 | + |
| 100 | +Then visit `web/target/web/public/main/index.html` to browse the main page in release mode. |
| 101 | + |
| 102 | +### Test |
| 103 | + |
| 104 | +Run the following command: |
| 105 | + |
| 106 | +``` shell |
| 107 | +sbt test |
| 108 | +``` |
| 109 | + |
| 110 | +Then the examples in Scaladoc comments will be ran by ScalaTest. |
0 commit comments