Skip to content

Commit 4b5f2df

Browse files
build: minify html and js and default to esm cdn. (#27)
1 parent b968a55 commit 4b5f2df

7 files changed

Lines changed: 781 additions & 13 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: npm ci
3333

3434
- name: Build Production Site
35-
run: npm run build:esm
35+
run: npm run build
3636

3737
- name: Setup Pages
3838
uses: actions/configure-pages@v5.0.0

docs/build-and-deploy.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This project uses two runtime modes:
44

55
- Local development mode: dynamic CDN resolution from `src/modules/cdn.js` with esm.sh as default.
6-
- Production mode: CDN-first build artifacts in `dist`, with `build:esm` as the current preferred deploy build.
6+
- Production mode: CDN-first build artifacts in `dist`, with `npm run build` defaulting to ESM unless `KNIGHTED_PRIMARY_CDN` is set.
77

88
## Local Development
99

@@ -29,6 +29,7 @@ Select a different production primary CDN at build time:
2929
```sh
3030
KNIGHTED_PRIMARY_CDN=esm npm run build
3131
KNIGHTED_PRIMARY_CDN=jspmGa npm run build
32+
KNIGHTED_PRIMARY_CDN=importMap npm run build
3233
```
3334

3435
Convenience scripts are also available:
@@ -44,25 +45,29 @@ npm run build:importmap-mode
4445
<!-- prettier-ignore-start -->
4546
| Mode | Resolver | Import map step | JSPM index needed | Typical use |
4647
| --- | --- | --- | --- | --- |
47-
| `importMap` | Import map in `dist/index.html` | Yes | Yes | Default production mode |
48-
| `esm` | `src/modules/cdn.js` (`esm.sh` primary) | No | No | Stable fallback mode |
48+
| `importMap` | Import map in `dist/index.html` | Yes | Yes | JSPM-indexed release builds |
49+
| `esm` | `src/modules/cdn.js` (`esm.sh` primary) | No | No | Current default and deploy mode |
4950
| `jspmGa` | `src/modules/cdn.js` (`ga.jspm.io` primary) | No | No | Direct ga.jspm.io testing |
5051
<!-- prettier-ignore-end -->
5152

5253
Mode notes:
5354

5455
- `importMap`: Import-map mode when JSPM has indexed the required graph.
55-
- `esm`: Current preferred deploy build mode.
56+
- `esm`: Current default `build` mode and preferred deploy build mode.
5657
- `jspmGa`: Direct ga.jspm.io URL mode without import-map generation.
5758

58-
This runs two steps:
59+
`npm run build` runs five steps:
5960

6061
1. `npm run build:prepare`
6162

6263
- Copies `src` to `dist`
6364
- Injects `window.__KNIGHTED_PRIMARY_CDN__` into `dist/index.html`
6465

65-
2. `npm run build:importmap`
66+
2. `npm run build:css`
67+
68+
- Bundles and minifies `dist/styles.css` with Lightning CSS
69+
70+
3. `npm run build:importmap`
6671

6772
- Runs only when `KNIGHTED_PRIMARY_CDN=importMap`
6873
- Runs `jspm link` with `--provider jspm.io`
@@ -74,6 +79,15 @@ This runs two steps:
7479
- Traces generated `dist/prod-imports.js`
7580
- Import specifiers come from `importMap` entries in `src/modules/cdn.js` (`cdnImportSpecs`)
7681

82+
4. `npm run build:js`
83+
84+
- Minifies `dist/**/*.js` and `dist/**/*.mjs` with esbuild
85+
- Uses syntax + whitespace minification only (no identifier mangling)
86+
87+
5. `npm run build:html`
88+
89+
- Minifies `dist/index.html` with `html-minifier-terser`
90+
7791
Preview the built site locally:
7892

7993
```sh
@@ -86,11 +100,13 @@ End-to-end tests run against a preview build by default:
86100
npm run test:e2e
87101
```
88102

89-
This command builds with `build:esm` first, then runs Playwright against the preview server.
103+
This command forces `KNIGHTED_PRIMARY_CDN=esm` and runs `npm run build` first, then runs Playwright against the preview server.
104+
105+
`preview` also forces an ESM build (`KNIGHTED_PRIMARY_CDN=esm npm run build`) before serving `dist`.
90106

91107
## CI And Deployment
92108

93-
- CI workflow (`.github/workflows/ci.yml`) installs dependencies, runs lint, and runs `npm run build`.
109+
- CI workflow (`.github/workflows/ci.yml`) installs dependencies, runs lint, and runs `npm run build:esm`.
94110
- Deploy workflow (`.github/workflows/deploy.yml`) builds the production site and publishes `dist` to GitHub Pages.
95111

96112
## Notes

0 commit comments

Comments
 (0)