From 399886ce8aefdb9903b2749149066c5fb0730570 Mon Sep 17 00:00:00 2001 From: Neil Derraugh Date: Sat, 29 Nov 2025 12:06:18 -0500 Subject: [PATCH 1/3] Add scalajs-vite-mill.md - content is copied from scalajs-vite.md to help in diff --- doc/tutorial/scalajs-vite-mill.md | 359 ++++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 doc/tutorial/scalajs-vite-mill.md diff --git a/doc/tutorial/scalajs-vite-mill.md b/doc/tutorial/scalajs-vite-mill.md new file mode 100644 index 0000000..b8ac271 --- /dev/null +++ b/doc/tutorial/scalajs-vite-mill.md @@ -0,0 +1,359 @@ +--- +layout: doc +title: Getting Started with Scala.js and Vite +--- + +In this first tutorial, we learn how to get started with Scala.js and [Vite](https://vitejs.dev/). +We use Vite to provide live-reloading of the Scala.js application in the browser for development. +We also configure it to build a minimal bundle for production. + +Going through this tutorial will make sure you understand the basic building blocks. +If you prefer to skip this step and directly write Scala.js code, you may jump to [Getting Started with Scala.js and Laminar](./laminar.html). + +If you prefer to look at the end result for this tutorial directly, checkout [the scalajs-vite-end-state branch](https://github.com/sjrd/scalajs-sbt-vite-laminar-chartjs-example/tree/scalajs-vite-end-state) instead of creating everything from scratch. + +## Prerequisites + +Make sure to install [the prerequisites](./index.html#prerequisites) before continuing further. + +## Vite template + +We bootstrap our setup using the vanilla Vite template. +Navigate to a directory where you store projects, and run the command + +{% highlight shell %} +$ npm create vite@4.1.0 +{% endhighlight %} + +Choose a project name (we choose `livechart`). +Select the "Vanilla" framework and the "JavaScript" variant. +Our output gives: + +{% highlight shell %} +$ npm create vite@4.1.0 +Need to install the following packages: + create-vite@4.1.0 +Ok to proceed? (y) +✔ Project name: … livechart +✔ Select a framework: › Vanilla +✔ Select a variant: › JavaScript + +Scaffolding project in .../livechart... + +Done. Now run: + + cd livechart + npm install + npm run dev +{% endhighlight %} + +As instructed, we follow up with + +{% highlight shell %} +$ cd livechart +$ npm install +[...] +$ npm run dev + + VITE v4.1.4 ready in 156 ms + + ➜ Local: http://localhost:5173/ + ➜ Network: use --host to expose + ➜ press h to show help +{% endhighlight %} + +Open the provided URL to see the running JavaScript-based hello world. + +### Exploring the template + +In the generated folder, we find the following relevant files: + +* `index.html`: the main web page; it contains a `