Skip to content

Commit 49a0c3c

Browse files
committed
.
1 parent d71308b commit 49a0c3c

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

site/docs/_docs/deployment.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,130 @@ This project targets the dev loop. When comes to deploy however, I always hit th
1717
1818
This project provides a tiny helper library and an opinionated strategy to get over this hurdle, following exacltly the strategy laid out above.
1919

20+
# Scala-cli
2021

22+
I don't think it's possible run client side routing out of scala CLI, as you need to have control over the backend. However, it's easily possible to deploy a static site build with scalaJS to github pages.
2123

24+
buildJs
25+
```sh
26+
mkdir -p {{outDir}}
27+
scala-cli --power package . -o {{outDir}} -f --js-mode release
28+
```
2229

2330

31+
32+
33+
34+
Yaml
35+
36+
```yaml
37+
name: Continuous Integration
38+
39+
on:
40+
push:
41+
branches: ['main']
42+
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
ACTIONS_STEP_DEBUG: true
46+
47+
concurrency:
48+
group: ${{ github.workflow }} @ ${{ github.ref }}
49+
cancel-in-progress: true
50+
51+
jobs:
52+
build:
53+
name: build
54+
if: github.ref == 'refs/heads/main'
55+
strategy:
56+
matrix:
57+
os: [ubuntu-latest]
58+
runs-on: ${{ matrix.os }}
59+
timeout-minutes: 60
60+
steps:
61+
- uses: actions/checkout@v3
62+
with:
63+
fetch-depth: 0
64+
- uses: coursier/cache-action@v6.3
65+
- uses: VirtusLab/scala-cli-setup@main
66+
with:
67+
power: true
68+
jvm: temurin:21
69+
- uses: taiki-e/install-action@just
70+
- name: Setup Pages
71+
uses: actions/configure-pages@v4
72+
- run: just buildJs
73+
- run: just copyAssets
74+
- name: Setup Pages
75+
uses: actions/configure-pages@v4
76+
- uses: actions/upload-artifact@v3
77+
with:
78+
name: page
79+
path: /home/runner/work/indigoLite/indigoLite/.out/
80+
if-no-files-found: error
81+
deploy:
82+
needs: build
83+
permissions:
84+
pages: write
85+
id-token: write
86+
environment:
87+
name: github-pages
88+
url: ${{ steps.deployment.outputs.page_url }}
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: actions/download-artifact@v3
92+
with:
93+
name: page
94+
path: .
95+
- uses: actions/configure-pages@v4
96+
- uses: actions/upload-pages-artifact@v2
97+
with:
98+
path: .
99+
- name: Deploy to GitHub Pages
100+
id: deployment
101+
uses: actions/deploy-pages@v3
102+
```
103+
104+
105+
# Mill
106+
107+
In build.sc, create new tasks for assembly, that put the JS and static assets in the resources.
108+
109+
```scala sc:nocompile
110+
object backend extends Common with ScalafmtModule with ScalafixModule {
111+
def frontendResources = T{PathRef(frontend.fullLinkJS().dest.path)}
112+
113+
def staticAssets = T.source{PathRef(frontend.millSourcePath / "ui")} // index.html is here
114+
115+
def allClasspath = T{localClasspath() ++ Seq(frontendResources()) ++ Seq(staticAssets()) }
116+
117+
override def assembly: T[PathRef] = T{
118+
Assembly.createAssembly(
119+
Agg.from(allClasspath().map(_.path)),
120+
manifest(),
121+
prependShellScript(),
122+
Some(upstreamAssembly2().pathRef.path),
123+
assemblyRules
124+
)
125+
}
126+
127+
def ivyDeps = super.ivyDeps() ++ Seq(ivy"io.github.quafadas::frontend-routes:{{projectVersion}}")
128+
}
129+
130+
```
131+
132+
For the server, we then need to setup some routes, which reference this;
133+
134+
```
135+
136+
```
137+
138+
This is aliased as
139+
140+
```scala sc:nocompile
141+
val allFrontendRoutes = io.github.quafadas.sjsls.defaultFrontendRoutes[IO]("ui")
142+
```
143+
144+
For convience. It is not hard to track back through this code to see what's it's doing - it the JS from the server root, and any time it detects a request beginning with `ui`, simply returns `index.html`.
145+
146+
Remember - there is no misdirection as is common with bundlers and whatnot. Use the browser tools to help you see what's happening - it's extremely transparent.

0 commit comments

Comments
 (0)