Skip to content

Commit 4793741

Browse files
committed
static/_headers gets built on build
1 parent 5ef597a commit 4793741

File tree

5 files changed

+11
-45
lines changed

5 files changed

+11
-45
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ firebase.json
7474
# Misc
7575
.tmp
7676
.lycheecache
77+
78+
# This is now a build artifact
79+
static/_headers

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,24 @@ hugo server
8888
#### HTTP Headers Configuration
8989

9090
The `static/_headers` file is automatically generated from
91-
`scripts/_headers.config.ts`. **Do not edit `static/_headers` directly** - your
92-
changes will be overwritten.
91+
`scripts/_headers.config.ts` during the build process. **Do not edit `static/_headers`
92+
directly** or commit it to git - it is a build artifact that will be regenerated.
9393

9494
##### Making Changes to Headers
9595

9696
1. Edit `scripts/_headers.config.ts` (the source of truth with readable format
9797
and TypeScript type safety)
98-
2. Generate the headers file:
98+
2. Test your changes locally by generating the headers file:
9999
```sh
100100
npm run build:headers
101101
```
102-
3. Commit both files - a git pre-commit hook will automatically regenerate
103-
`static/_headers` when you modify `scripts/_headers.config.ts`
102+
3. Commit only `scripts/_headers.config.ts` - the `_headers` file will be
103+
generated automatically during deployment
104104

105-
##### Automatic Synchronization
105+
##### Build-Time Generation
106106

107-
The files stay in sync automatically through:
108-
109-
- **Pre-commit hook** - Regenerates `_headers` when `_headers.config.ts` changes
110-
- **Build process** - `build.sh` regenerates before deployment
111-
- **Manual generation** - Run `npm run build:headers` anytime
107+
The headers file is generated automatically during deployment via `build.sh`.
108+
You can also generate it manually for local testing with `npm run build:headers`.
112109

113110
The TypeScript config format provides:
114111

git/hooks/pre-commit

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,4 @@ function timed_run() {
2424
fi
2525
}
2626

27-
# Regenerate static/_headers from _headers.config.ts if it changed
28-
if git diff --cached --name-only | grep -q "scripts/_headers.config.ts"; then
29-
echo "Detected changes to scripts/_headers.config.ts, regenerating static/_headers..."
30-
npx tsx scripts/generate-headers.ts
31-
git add static/_headers
32-
echo "✅ Updated static/_headers and added to commit"
33-
fi
34-
35-
# Also regenerate if the generator script itself changed
36-
if git diff --cached --name-only | grep -q "scripts/generate-headers.ts"; then
37-
echo "Detected changes to generator script, regenerating static/_headers..."
38-
npx tsx scripts/generate-headers.ts
39-
git add static/_headers
40-
echo "✅ Updated static/_headers and added to commit"
41-
fi
42-
4327
timed_run "precious lint" "precious lint --staged"

scripts/_headers.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
* HTTP Headers Configuration for Cloudflare Pages
33
* This file is the source of truth for static/_headers generation
44
* Run: npm run build:headers
5-
*
6-
* Note: This file lives in scripts/ (not static/) to avoid deploying
7-
* TypeScript source files to production.
85
*/
96

107
interface HeadersConfig {

static/_headers

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)