|
| 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