@@ -22,17 +22,17 @@ We bootstrap our setup using the vanilla Vite template.
2222Navigate to a directory where you store projects, and run the command
2323
2424{% highlight shell %}
25- $ npm create vite@4.1 .0
25+ $ npm create vite@6.5 .0
2626{% endhighlight %}
2727
2828Choose a project name (we choose ` livechart ` ).
2929Select the "Vanilla" framework and the "JavaScript" variant.
3030Our output gives:
3131
3232{% highlight shell %}
33- $ npm create vite@4.1 .0
33+ $ npm create vite@6.5 .0
3434Need to install the following packages:
35- create-vite@4.1 .0
35+ create-vite@6.5 .0
3636Ok to proceed? (y)
3737✔ Project name: … livechart
3838✔ Select a framework: › Vanilla
@@ -55,11 +55,11 @@ $ npm install
5555[ ...]
5656$ npm run dev
5757
58- VITE v4.1.4 ready in 156 ms
58+ VITE v6.3.5 ready in 156 ms
5959
6060 ➜ Local: http://localhost:5173/
6161 ➜ Network: use --host to expose
62- ➜ press h to show help
62+ ➜ press h + enter to show help
6363{% endhighlight %}
6464
6565Open the provided URL to see the running JavaScript-based hello world.
@@ -69,12 +69,12 @@ Open the provided URL to see the running JavaScript-based hello world.
6969In the generated folder, we find the following relevant files:
7070
7171* ` index.html ` : the main web page; it contains a ` <script type=module src="/main.js"> ` referencing the main JavaScript entry point.
72- * ` main.js ` : the main JavaScript entry point; it sets up some DOM elements, and sets up a counter for a button.
73- * ` counter.js ` : it implements a counter functionality for a button.
72+ * ` /src/ main.js` : the main JavaScript entry point; it sets up some DOM elements, and sets up a counter for a button.
73+ * ` /src/ counter.js` : it implements a counter functionality for a button.
7474* ` package.json ` : the config file for ` npm ` , the JavaScript package manager and build orchestrator.
7575
7676Remarkably, there is no ` vite.config.js ` file, which would be the configuration for Vite itself.
77- Vite gives a decent experience out of the box, without any configuration.
77+ Vite gives a decent experience out of the box, without any configuration, but we will need one soon enough .
7878
7979### Live changes
8080
@@ -99,12 +99,12 @@ Observe that the page automatically and instantaneously refreshes to show the ch
9999We use [ sbt] ( https://www.scala-sbt.org/ ) as a build tool for Scala and Scala.js.
100100We set it up as follows.
101101
102- In the subdirectory ` livechart/ project/` , we add two files: ` build.properties ` and ` plugins.sbt ` .
102+ Create the subdirectory ` project/ ` , and add two files: ` build.properties ` and ` plugins.sbt ` .
103103
104104* ` project/build.properties ` : set the version of sbt
105105
106106{% highlight plaintext %}
107- sbt.version=1.10.0
107+ sbt.version=1.11.3
108108{% endhighlight %}
109109
110110* ` project/plugins.sbt ` : declare sbt plugins; in this case, only sbt-scalajs
@@ -113,7 +113,7 @@ sbt.version=1.10.0
113113addSbtPlugin("org.scala-js" % "sbt-scalajs" % "{{ site.versions.scalaJS }}")
114114{% endhighlight %}
115115
116- At the root of our ` livechart/ ` project, we add one file: ` build.sbt ` .
116+ At the root of our project, we add one file: ` build.sbt ` .
117117
118118* ` build.sbt ` : the main sbt build
119119
@@ -123,7 +123,7 @@ import org.scalajs.linker.interface.ModuleSplitStyle
123123lazy val livechart = project.in(file("."))
124124 .enablePlugins(ScalaJSPlugin) // Enable the Scala.js plugin in this project
125125 .settings(
126- scalaVersion := "3.3.3 ",
126+ scalaVersion := "3.7.1 ",
127127
128128 // Tell Scala.js that this is an application with a main method
129129 scalaJSUseMainModuleInitializer := true,
@@ -158,8 +158,8 @@ import scala.scalajs.js.annotation.*
158158
159159import org.scalajs.dom
160160
161- // import javascriptLogo from "/javascript.svg"
162- @js .native @JSImport ("/javascript.svg", JSImport.Default)
161+ // import javascriptLogo from "/src/ javascript.svg"
162+ @js .native @JSImport ("/src/ javascript.svg", JSImport.Default)
163163val javascriptLogo: String = js.native
164164
165165@main
@@ -206,13 +206,13 @@ The definition of `javascriptLogo` deserves some explanation.
206206We translated it from the JavaScript import
207207
208208{% highlight javascript %}
209- import javascriptLogo from "/javascript.svg"
209+ import javascriptLogo from "/src/ javascript.svg"
210210{% endhighlight %}
211211
212212which is actually a shorthand for
213213
214214{% highlight javascript %}
215- import { default as javascriptLogo } from "/javascript.svg"
215+ import { default as javascriptLogo } from "/src/ javascript.svg"
216216{% endhighlight %}
217217
218218Many bundlers, Vite included, treat ` import ` s with asset files such as ` .svg ` as pseudo-modules whose ` default ` import is the * file path* to the corresponding asset in the processed bundle.
@@ -222,12 +222,12 @@ Read more about this mechanism [in the Vite documentation on static asset handli
222222The translation in Scala.js reads as
223223
224224{% highlight scala %}
225- @js .native @JSImport ("/javascript.svg", JSImport.Default)
225+ @js .native @JSImport ("/src/ javascript.svg", JSImport.Default)
226226val javascriptLogo: String = js.native
227227{% endhighlight %}
228228
229229The ` @js.native ` annotation tells Scala.js that ` javascriptLogo ` is provided externally by JavaScript.
230- The ` @JSImport("/javascript.svg", JSImport.Default) ` is the translation of the ` default ` import from the ` /javascript.svg ` pseudo-module.
230+ The ` @JSImport("/src/ javascript.svg", JSImport.Default) ` is the translation of the ` default ` import from the ` /src /javascript.svg` pseudo-module.
231231Since it represents a file path, we declare ` javascriptLogo ` as a ` String ` .
232232
233233The ` = js.native ` is a Scala.js idiosyncrasy: we need a concrete value to satisfy the Scala typechecker.
@@ -285,7 +285,7 @@ Let us change the message to
285285
286286{% highlight diff %}
287287 <a href =" https://developer.mozilla.org/en-US/docs/Web/JavaScript " target =" _blank " >
288- <img src =" /javascript.svg " class =" logo vanilla " alt =" JavaScript logo " />
288+ <img src =" /src/ javascript.svg " class =" logo vanilla " alt =" JavaScript logo " />
289289 </a >
290290- <h1>Hello Scala.js!</h1>
291291+ <h1>Hello Scala.js and Vite!</h1>
@@ -319,7 +319,7 @@ $ npm run build
319319> livechart@0.0.0 build
320320> vite build
321321
322- vite v4.1.4 building for production...
322+ vite v6.3.5 building for production...
323323[ info] welcome to sbt 1.8.0 (Temurin Java 1.8.0_362)
324324[ ...]
325325[ info] Full optimizing .../livechart/target/scala-3.2.2/livechart-opt
0 commit comments