Skip to content

Commit 301ff0d

Browse files
build: cdn management. (#1)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a2857c8 commit 301ff0d

14 files changed

Lines changed: 2450 additions & 1403 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ jobs:
3232
path: npm-debug.log
3333

3434
- name: Lint
35-
run: npm run lint
35+
run: npm run lint
36+
37+
- name: Build
38+
run: npm run build:esm

.github/workflows/deploy.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ jobs:
2626
- name: Checkout
2727
uses: actions/checkout@v6.0.1
2828

29-
- name: Package static site
30-
run: |
31-
mkdir -p build
32-
cp -r src/* build/
29+
- name: Setup Node
30+
uses: actions/setup-node@v6.2.0
31+
with:
32+
node-version: '24.14.0'
33+
34+
- name: Install Dependencies
35+
run: npm ci
36+
37+
- name: Build Production Site
38+
run: npm run build:esm
3339

3440
- name: Setup Pages
3541
uses: actions/configure-pages@v5.0.0
3642

3743
- name: Upload Pages artifact
3844
uses: actions/upload-pages-artifact@v3.0.1
3945
with:
40-
path: build
46+
path: dist
4147

4248
- name: Deploy to GitHub Pages
4349
id: deployment

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
dist

.oxlintrc.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"plugins": ["import"],
34
"categories": {
45
"correctness": "error",
56
"suspicious": "warn",
@@ -11,6 +12,17 @@
1112
"no-console": "error",
1213
"no-unused-vars": "error",
1314
"no-shadow": "error",
15+
"import/no-cycle": "error",
16+
"import/no-duplicates": "error",
17+
"import/no-self-import": "error",
18+
"import/no-unresolved": "error"
1419
},
15-
"ignorePatterns": ["dist/**", "coverage/**", "vendor/**", "test/snapshots/**", "node_modules/**"]
16-
}
20+
"ignorePatterns": [
21+
"dist/**",
22+
".tmp-jspm-sass/**",
23+
"coverage/**",
24+
"vendor/**",
25+
"test/snapshots/**",
26+
"node_modules/**"
27+
]
28+
}

docs/build-and-deploy.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Build And Deploy
2+
3+
This project uses two runtime modes:
4+
5+
- Local development mode: dynamic CDN resolution from `src/cdn.js` with esm.sh as default.
6+
- Production mode: JSPM-generated import map injected into `dist/index.html` and hosted on GitHub Pages.
7+
8+
## Local Development
9+
10+
Install dependencies and start the local server:
11+
12+
```sh
13+
npm ci
14+
npm run dev
15+
```
16+
17+
The app loads from `src/index.html` and keeps the dynamic CDN fallback behavior for fast iteration and debugging.
18+
19+
## Production Build
20+
21+
Create a production-ready `dist` folder:
22+
23+
```sh
24+
npm run build
25+
```
26+
27+
Select a different production primary CDN at build time:
28+
29+
```sh
30+
KNIGHTED_PRIMARY_CDN=esm npm run build
31+
KNIGHTED_PRIMARY_CDN=jspmGa npm run build
32+
```
33+
34+
Convenience scripts are also available:
35+
36+
```sh
37+
npm run build:esm
38+
npm run build:jspm
39+
npm run build:importmap-mode
40+
```
41+
42+
### Build Mode Matrix
43+
44+
<!-- prettier-ignore-start -->
45+
| Mode | Resolver | Import map step | JSPM index needed | Typical use |
46+
| --- | --- | --- | --- | --- |
47+
| `importMap` | Import map in `dist/index.html` | Yes | Yes | Default production mode |
48+
| `esm` | `src/cdn.js` (`esm.sh` primary) | No | No | Stable fallback mode |
49+
| `jspmGa` | `src/cdn.js` (`ga.jspm.io` primary) | No | No | Direct ga.jspm.io testing |
50+
<!-- prettier-ignore-end -->
51+
52+
Mode notes:
53+
54+
- `importMap`: Preferred production mode when JSPM has indexed the required graph.
55+
- `esm`: Stable fallback mode while waiting on JSPM indexing.
56+
- `jspmGa`: Direct ga.jspm.io URL mode without import-map generation.
57+
58+
This runs two steps:
59+
60+
1. `npm run build:prepare`
61+
62+
- Copies `src` to `dist`
63+
- Injects `window.__KNIGHTED_PRIMARY_CDN__` into `dist/index.html`
64+
65+
2. `npm run build:importmap`
66+
67+
- Runs only when `KNIGHTED_PRIMARY_CDN=importMap`
68+
- Runs `jspm link` with `--provider jspm.io`
69+
- Injects an inline import map into `dist/index.html`
70+
- Adds integrity metadata and modulepreload links
71+
- Pins the following packages through resolution overrides:
72+
- `sass=1.93.2`
73+
- `less=4.4.2`
74+
- Traces generated `dist/prod-imports.js`
75+
- Import specifiers come from `importMap` entries in `src/cdn.js` (`cdnImportSpecs`)
76+
77+
Preview the built site locally:
78+
79+
```sh
80+
npm run preview
81+
```
82+
83+
## CI And Deployment
84+
85+
- CI workflow (`.github/workflows/ci.yml`) installs dependencies, runs lint, and runs `npm run build`.
86+
- Deploy workflow (`.github/workflows/deploy.yml`) builds the production site and publishes `dist` to GitHub Pages.
87+
88+
## Notes
89+
90+
- In production, the preferred/default mode is import-map-based resolution (`window.__KNIGHTED_PRIMARY_CDN__ = "importMap"`).
91+
- In `importMap` mode, runtime resolution is import-map first; if a specifier is missing from the generated map, runtime falls back through the CDN
92+
provider chain configured in `src/cdn.js`.
93+
- In `esm` and `jspmGa` modes, runtime resolution is handled entirely by the CDN provider chain configured in `src/cdn.js` without an import map.
94+
95+
### Sass Loading Gotchas
96+
97+
- Symptom: switching to Sass mode shows `Unable to load Sass compiler for browser usage: Dynamic require of "url" is not supported`.
98+
- Cause: some `esm.sh` Sass outputs currently include runtime paths that are not browser-safe for this app.
99+
- Current mitigation: `src/cdn.js` keeps `esm.sh` first, then falls back to `unpkg` for Sass via `sass@1.93.2/sass.default.js?module`.
100+
- Important context: this can appear even if the Sass URL has not changed in this repo, because CDN-transformed module output can change upstream.
101+
- If this regresses again:
102+
- Verify Sass import candidates in `src/cdn.js`.
103+
- Reproduce directly in browser devtools with `await import('<candidate-url>')`.
104+
- Keep at least one known browser-safe fallback provider in the Sass candidate list.

0 commit comments

Comments
 (0)