How to batch convert ttf to woff in a build script
- Step 1Install pako — npm install pako. The Node-side WOFF wrapper logic is identical to the browser version — wrap the sfnt header, deflate each table, write the WOFF file.
- Step 2Walk the fonts directory — Use fs.readdir to find every *.ttf and *.otf in src/fonts/. For each, call the WOFF wrapper helper and write the output to public/fonts/<name>.woff.
- Step 3Add a CI guard — In GitHub Actions, run the script then git diff --exit-code public/fonts/. If a developer adds a TTF without committing the matched WOFF, CI fails the PR.
Frequently asked questions
Should I run WOFF and WOFF2 conversion in parallel?+
Yes — they're independent. Run both scripts as a single npm prebuild step, both writing to public/fonts/. The two formats coexist happily; modern browsers pick WOFF2 via format() hints and IE11 falls back to WOFF.
Can I parallelise the conversion?+
Yes. Promise.all over your file list with a concurrency limit of 8–16 (typical CPU core count). pako is pure JS so each compression is single-threaded — limiting concurrency prevents oversubscription.
What about variable fonts?+
Variable fonts wrap to WOFF the same way as static fonts. The fvar/gvar tables are preserved and font-variation-settings CSS still works after conversion.
Is the WOFF output deterministic?+
Yes. Same input → same output bytes. This is important for reproducible builds and CI cache hits — if the input TTF doesn't change, the WOFF output won't either.
Privacy first
Every JAD Font tool runs entirely in your browser using opentype.js and the wawoff2 WASM Brotli encoder. Your fonts never leave your device — verified by zero outbound network requests during processing.