Skip to content

Tutorials for getting started with Scala.js, Vite, Laminar and ST #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 25, 2023

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Nov 28, 2022

These tutorials are the written equivalent of recent talks I made at ScalaCon and Scala.IO, as well as videos I recorded at the Scala Center: https://www.youtube.com/watch?v=dv7fPmgFTNA and https://www.youtube.com/watch?v=UePrOa_1Am8

There are probably things we can significantly improve for the website. Some open questions:

  • How to property "advertize" these tutorials. Currently they are a bit hidden.
  • Should we split the Laminar+ST tutorial? It is a bit large in written form.

Comments welcome!

@sjrd sjrd changed the title Getting started with laminar Tutorials for getting started with Scala.js, Vite, Laminar and ST Nov 28, 2022
@raquo
Copy link
Contributor

raquo commented Nov 28, 2022

Since the tutorials page is so small, maybe move its contents to the parent https://www.scala-js.org/doc/ ?

As a reference, for Laminar itself, I think our combined learning resources page https://laminar.dev/resources works reasonably well... or at least, nobody has so far spoken up to suggest doing it differently :)

Copy link

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful!

I agree that the ScalablyTyped part could be moved out of the Laminar part. But in the end, they talk about the same program so it may require significant work to arrange things to make them more independent of each other… I am fine with keeping them together as well.

Comment on lines 9 to 10
* [Getting Started with Scala.js, Vite, Laminar and ScalablyTyped](./getting-started/)
* [Basic tutorial](./basic/) to get you started

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear which one should be picked. If I am a new user, do I have a good reason to pick the basic tutorial?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be valuable for the readers to know here the type of environment they will get (live-reloading, production build, interop with JS) more than the technical solutions to achieve that (Vite and ScalablyTyped).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is part of the open questions on how to advertise this tutorial appropriately. The top-level pages probably need to be rethought.

@sjrd sjrd force-pushed the getting-started-with-laminar branch from cb988a8 to 210e992 Compare November 30, 2022 17:06
Copy link
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Releasing the one comment I had. I won't get to this before a couple of days 🤷

{% endhighlight %}

Since the built website uses an ECMAScript module, we need to serve it through an HTTP server to visualize it.
We use the npm application `http-server` for that purpose, as we can run it without any additional dependency:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite serve iiuc is able to do that. Might need some config, but is likely perceived less overhead than another command.

Copy link

@julienrf julienrf Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vite by default builds the non-optimized app. But indeed there is a vite preview command to locally view the production build: https://vitejs.dev/guide/cli.html#vite-preview. Does it work here?

@oyvindberg
Copy link

Sorry, I'm late to the party here. Thanks for adding this, these are incredibly useful pointers for beginners!

I agree with @julienrf that mixing ST and Laminar in the same tutorial probably should probably be avoided - I think it's fairly unlikely that a beginner interested in one of them is also interested in the other at the same time.

How about we make the Laminar tutorial something more todo-listy, and then extract the chart.js / ST pieces into its own tutorial? I can contribute some hours towards extracting the ST parts into it's own page.

@sjrd sjrd force-pushed the getting-started-with-laminar branch 3 times, most recently from 9f7096b to 97ca306 Compare February 1, 2023 10:29
@sjrd
Copy link
Member Author

sjrd commented Feb 1, 2023

I have finally found enough time to decompose the tutorial. There is now a Laminar-only tutorial, and then a separate one for ScalablyTyped. The Laminar tutorial is entirely available on Scribble for people to see the end result and play with it.

Copy link

@Sporarum Sporarum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have minor stylistic comments, but apart from that, it looks good to me !

@sjrd sjrd force-pushed the getting-started-with-laminar branch from 97ca306 to e1d7ca3 Compare February 1, 2023 13:26
@sjrd sjrd marked this pull request as ready for review February 1, 2023 13:43
@sjrd sjrd requested a review from gzm0 February 1, 2023 13:43
@sjrd sjrd force-pushed the getting-started-with-laminar branch from f0567ac to 1615fdf Compare February 2, 2023 08:58
Copy link
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All-in-all this looks very nice. I have left minor comments. However, two bigger things stand out:

  • There is no testing. IMO the vite tutorial and the laminar tutorial both need some input there (vite: how to set it up, laminar: how to test RFP).
  • The build integration with vite seems suboptimal. OK to try it out, not good enough to recommend it as part of a tutorial IMO.

@sjrd
Copy link
Member Author

sjrd commented Mar 15, 2023

OK, I have finally updated everything to use the published vite-plugin-scalajs. I have also addressed other comments, such as adding a testing section in the Laminar tutorial (I did not do it in the Vite setup to keep it to the minimum).

This is ready for a new round of review.

@sjrd sjrd requested a review from gzm0 March 15, 2023 09:56
Copy link

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I wonder if we can simplify even further the first tutorial. See my comment below.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me! There is maybe one thing that could be simplified though. We start with a Vite template where we “undo” some things (e.g. we remove the .js files) before we set up Scala.js. I wonder if it would be simpler to provide a template that has the Scala.js integration from the beginning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a possibility, of course. That would significantly change the flow of the tutorial. The idea for that was that the example repo branches would address this:

If you prefer to navigate the end result for this tutorial directly, checkout the scalajs-vite-end-state branch instead of creating everything from scratch.

The next tutorial about Laminar also suggests to directly clone that branch to start off.


{% highlight javascript %}
import './style.css'
import 'scalajs:main.js'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment explaining how Vite handles this import?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sjrd added 3 commits March 23, 2023 11:24
The bundle contains: CSS, Diff, HTML/XML, JSON, JavaScript,
Less, Plain text, Scala, SCSS, Shell Session, TypeScript.
@sjrd sjrd force-pushed the getting-started-with-laminar branch from 05ebc71 to a933c2c Compare March 23, 2023 10:27
@sjrd
Copy link
Member Author

sjrd commented Mar 23, 2023

Upgraded to Laminar 15.0.1, which was released today.

@gzm0 When you get the chance, could you check that your main concerns were addressed (test setup and vite-plugin setup)? If they are, I think we could merge this as improvement over the status quo, even if perhaps further refinements could come later?

Copy link
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Only minor comments from my side.

* `project/plugins.sbt`: declare sbt plugins; in this case, only sbt-scalajs

{% highlight scala %}
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the scala.js version variable so this stays up to date? (or is this deliberate?)

/* Depend on the scalajs-dom library.
* It provides static types for the browser DOM APIs.
*/
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.4.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (variable version)?

We start here with the project setup developed in the previous tutorial about [Setting up Scala.js with Vite](./scalajs-vite.html).
To follow along this tutorial, either use the result of the previous tutorial, or checkout [the scalajs-vite-end-state branch](https://github.com/sjrd/scalajs-sbt-vite-laminar-chartjs-example/tree/scalajs-vite-end-state) of the accompanying repo.

If you prefer to navigate the end result for this tutorial directly, checkout [the laminar-end-state branch](https://github.com/sjrd/scalajs-sbt-vite-laminar-chartjs-example/tree/laminar-end-state) instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you prefer to navigate the end result for this tutorial directly, checkout [the laminar-end-state branch](https://github.com/sjrd/scalajs-sbt-vite-laminar-chartjs-example/tree/laminar-end-state) instead.
If you prefer to look at the end result for this tutorial directly, checkout [the laminar-end-state branch](https://github.com/sjrd/scalajs-sbt-vite-laminar-chartjs-example/tree/laminar-end-state) instead.

Pretty sure "navigate" is correct english, but maybe a bit hard to understand? (same comment in other tutorials).

)
{% endhighlight %}

After re-importing the project in the IDE (which should be prompted), we create a new file `src/test/scala/livechart/ModelTest.scala`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean by "which should be prompted" here. Do you mean the IDE should show a prompt? Maybe just write "you should get a prompt"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the (...). It was not really necessary. If the IDE prompts, the user will see it; and if it doesn't for some reason, they won't puzzle over the fact that it doesn't.

@sjrd sjrd merged commit df42aae into scala-js:main Mar 25, 2023
@sjrd sjrd deleted the getting-started-with-laminar branch March 25, 2023 15:39
@sjrd
Copy link
Member Author

sjrd commented Mar 25, 2023

Thanks for the review :D Let's ship it 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants