-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
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 :) |
There was a problem hiding this 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.
doc/tutorial/index.md
Outdated
* [Getting Started with Scala.js, Vite, Laminar and ScalablyTyped](./getting-started/) | ||
* [Basic tutorial](./basic/) to get you started |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
cb988a8
to
210e992
Compare
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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 |
9f7096b
to
97ca306
Compare
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. |
There was a problem hiding this 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 !
97ca306
to
e1d7ca3
Compare
f0567ac
to
1615fdf
Compare
There was a problem hiding this 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.
1615fdf
to
70b9205
Compare
OK, I have finally updated everything to use the published This is ready for a new round of review. |
There was a problem hiding this 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The bundle contains: CSS, Diff, HTML/XML, JSON, JavaScript, Less, Plain text, Scala, SCSS, Shell Session, TypeScript.
Also address comments about tests and about unclear things.
05ebc71
to
a933c2c
Compare
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? |
There was a problem hiding this 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.
doc/tutorial/scalajs-vite.md
Outdated
* `project/plugins.sbt`: declare sbt plugins; in this case, only sbt-scalajs | ||
|
||
{% highlight scala %} | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.0") |
There was a problem hiding this comment.
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?)
doc/tutorial/scalajs-vite.md
Outdated
/* Depend on the scalajs-dom library. | ||
* It provides static types for the browser DOM APIs. | ||
*/ | ||
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (variable version)?
doc/tutorial/laminar.md
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
doc/tutorial/laminar.md
Outdated
) | ||
{% endhighlight %} | ||
|
||
After re-importing the project in the IDE (which should be prompted), we create a new file `src/test/scala/livechart/ModelTest.scala`. |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
Thanks for the review :D Let's ship it 🚀 |
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:
Comments welcome!