You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you had not stopped the `npm run dev` process with Vite, Vite will immediately pick up the changes and refresh the browser with our updated "Hello Scala.js!" message.
273
+
You may have to stop and restart the `npm run dev` process, so that Vite picks up the newly created configuration file.
274
+
Vite will refresh the browser with our updated "Hello Scala.js!" message.
255
275
256
276
## Live changes with Scala.js
257
277
@@ -288,129 +308,50 @@ This ensures that the development cycle remains as short as possible.
288
308
## Production build
289
309
290
310
The `fastLinkJS` task of sbt and the `npm run dev` task of Vite are optimized for incremental development.
291
-
For production, we want to perform more optimizations on the Scala.js side with `fullLinkJS`, and bundle minimized files with `npm run build`.
292
-
293
-
For that to work well, we need to conditionally wire the output of `fastLinkJS` (resp. `fullLinkJS`) to the input of Vite when it is in development mode (resp. production mode).
294
-
This requires some configuration in Vite.
295
-
296
-
We create the file `vite.config.js` at the root of our project, with the following content:
297
-
298
-
{% highlight javascript %}
299
-
import { spawnSync } from "child_process";
300
-
import { defineConfig } from "vite";
301
-
302
-
// Detect whether Vite runs in development or production mode
303
-
function isDev() {
304
-
return process.env.NODE_ENV !== "production";
305
-
}
306
-
307
-
// Utility to invoke a given sbt task and fetch its output
Navigate to the mentioned URL to see your website.
405
346
406
347
## Conclusion
407
348
408
-
In this tutorial, we saw how to configure Scala.js with Vite from the ground up.
349
+
In this tutorial, we saw how to configure Scala.js with Vite from the ground up using `@scala-js/vite-plugin-scalajs`.
409
350
We used sbt as our build tool, but the same effect can be achieved with any other Scala build tool, such as [Mill](https://com-lihaoyi.github.io/mill/) or [scala-cli](https://scala-cli.virtuslab.org/).
410
351
411
352
Our setup features the following properties:
412
353
413
354
* Development mode with live reloading: changing Scala source files automatically triggers recompilation and browser refresh.
414
-
* Production mode, wired to automatically take the `fullLinkJS` output of Scala.js, and producing a unique `.js` file.
355
+
* Production mode, wired to automatically take the fully optimized output of Scala.js, and producing a unique `.js` file.
415
356
416
357
In our [next tutorial about Laminar](./laminar.html), we will learn how to write UIs in idiomatic Scala code.
0 commit comments