Skip to content

Commit 37b3aae

Browse files
committed
.
1 parent dd8107b commit 37b3aae

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

site/docs/_docs/advantages.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Here are the key advantages of this approach:
2+
3+
- Getting started is cca 10 seconds and you are live reloading your changes in browser. No config.
4+
5+
- There is no bundling misdirection, so source maps work. You can [debug scalaJS straight out of VSCode](https://code.visualstudio.com/docs/nodejs/browser-debugging) by following the standard VSSCode debugging instructions.
6+
7+
- Because there's no seperate ecosystem or NPM to configure, configuring build and CI is a lot easier. No `node_modules` to worry about. I found that this simplicity infected everything around it.
8+
9+
- In terms of performance; NPM dependancies are loaded out the CDN. This is slow the first time - but seriously - check the network browser tools when you refresh the page. The second time they are all served out of browser cache - it takes 0ms. Even better, that cache _survives application redeployment!_. If you pre-load the (fat) "internal-" xxx dependancies scalaJS produces, this combination crushes page load times.
10+
11+
- You can use the same build tool for both backend and frontend, and share code between them.
12+
13+
- Unit testing the frontend with the [Playwright](https://playwright.dev/java/) java client suddenly bursts into life...
14+
- And be because it's all orchestrated in the same process - you can test the _styles_ and the interplay between the application state and styles which is where most of my bugs are.
15+
16+
- Your build becomes very simple. Here is a mill build.sc file that builds an assembly, including your static resources, frontend app and API. [Example project](https://github.com/Quafadas/mill-full-stack)
17+
18+
```scala sc:nocompile
19+
object backend extends Common with ScalafmtModule with ScalafixModule {
20+
21+
def ivyDeps =
22+
super.ivyDeps() ++ Config.jvmDependencies ++ Config.sharedDependencies
23+
24+
def moduleDeps = Seq(shared.jvm)
25+
26+
def frontendResources = T{PathRef(frontend.fullLinkJS().dest.path)}
27+
28+
def staticAssets = T.source{PathRef(frontend.millSourcePath / "ui")}
29+
30+
def allClasspath = T{localClasspath() ++ Seq(frontendResources()) ++ Seq(staticAssets()) }
31+
32+
override def assembly: T[PathRef] = T{
33+
Assembly.createAssembly(
34+
Agg.from(allClasspath().map(_.path)),
35+
manifest(),
36+
prependShellScript(),
37+
Some(upstreamAssembly2().pathRef.path),
38+
assemblyRules
39+
)
40+
}
41+
}
42+
43+
```
44+
A dockerfile that uses the assembly:
45+
46+
```Dockerfile
47+
FROM azul/zulu-openjdk-alpine:17
48+
49+
# See the GHA for building the assembly
50+
COPY "./out/backend/assembly.dest/out.jar" "/app/app.jar"
51+
52+
EXPOSE 8080
53+
54+
ENTRYPOINT [ "java", "-jar", "/app/app.jar" ]
55+
```
56+
57+
Here is a GHA, that deploys that assembly to [fly.io](https://fly.io).
58+
59+
```yaml
60+
name: Deploy to fly.io
61+
62+
on:
63+
push:
64+
branches: [main]
65+
66+
env:
67+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
68+
jobs:
69+
build:
70+
runs-on: ubuntu-latest
71+
72+
steps:
73+
- uses: actions/checkout@v2
74+
- uses: coursier/setup-action@main
75+
with:
76+
jvm: temurin@17
77+
apps: mill
78+
- uses: superfly/flyctl-actions/setup-flyctl@master
79+
- name: Build application
80+
run: mill show backend.assembly -j 0
81+
- name: Deploy to fly.io
82+
run: flyctl deploy --remote-only
83+
```
84+
You are live.

site/docs/_docs/caveats.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Bundlers
2+
3+
Much of the frontend world is setup assuming that you in fact, are using a bundler.
4+
5+
That means that not _all_ stuff on npm, can in fact be easily consumer through ESModules.
6+
7+
Examples;
8+
9+
https://github.com/SAP/ui5-webcomponents/discussions/9487
10+
11+
It is usually possible to work around such limitations, but it is not pain free.
12+
13+
I strongly suspect though that as time marches formward ESModules will become the norm, and this limitation will become irrelevant.
14+
15+
# Scale
16+
17+
This project is not backed by anyone making money from it. Support is therefore ad hoc and limited.

site/docs/sidebar.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
index: index.md
22
subsection:
3+
- page: advantages.md
34
- page: config.md
45
- page: motivation.md
56
- page: bundler.md
67
- page: motivation.md
7-
- page: deployment.md
8+
- page: deployment.md\
9+
- page: caveats.md

0 commit comments

Comments
 (0)