What are some good patterns for permanently including debugging code in a JS lib?
Eg: verbose logging, saving intermediate artifacts to disk, etc. But minimal / no perf impact in prod build.
I've done this in different ways, but never settled on patterns I'm really happy with.
Eg: verbose logging, saving intermediate artifacts to disk, etc. But minimal / no perf impact in prod build.
I've done this in different ways, but never settled on patterns I'm really happy with.
I figure out a solution for this (using Vite). Seems decent so far.
Written up here in case anyone else finds it useful: github.com/pdubroy/til/bl…
Written up here in case anyone else finds it useful: github.com/pdubroy/til/bl…
TLDR:
1️⃣ Use process.env.FIZZBUZZ_DEBUG
2️⃣ In dev, use Vite's `define` option to replace this with the build-time value of that var
3️⃣ In prod, replace with ""
4️⃣ Use `external` option so dev builds can import "fs" if it's available
5️⃣ In prod, install a noop shim for "fs"
1️⃣ Use process.env.FIZZBUZZ_DEBUG
2️⃣ In dev, use Vite's `define` option to replace this with the build-time value of that var
3️⃣ In prod, replace with ""
4️⃣ Use `external` option so dev builds can import "fs" if it's available
5️⃣ In prod, install a noop shim for "fs"
https://twitter.com/dubroy/status/1724509780369088542 ∙ Archived on 2025-03-28.