Strip debug code
@ttsc/strip removes configured function calls and debugger statements from the emit. It’s not a minifier or tree-shaker, it removes exactly the patterns you list, nothing else.
Install
npm install -D @ttsc/strip// tsconfig.json
{
"compilerOptions": {
"plugins": [{ "transform": "@ttsc/strip" }]
}
}With no extra configuration, the defaults are:
console.logconsole.debugassert.*debugger
So console.log(...) and debugger; disappear from your emit by default.
Custom patterns
Drop a strip.config.ts next to your tsconfig.json:
// strip.config.ts
import type { ITtscStripConfig } from "@ttsc/strip";
export default {
calls: ["logger.debug", "metrics.devOnly", "assert.*"],
statements: ["debugger"],
} satisfies ITtscStripConfig;calls: statement-level calls. Supports a.*wildcard at the end (e.g.assert.*matchesassert.equal,assert.deepStrictEqual, …).statements: bare statements. Currently supportsdebugger.
@ttsc/strip discovers its config by walking upward from the tsconfig directory, looking for strip.config.{ts,cts,mts,js,cjs,mjs,json}. To point at a specific file, set configFile on the tsconfig entry:
// tsconfig.json
{
"compilerOptions": {
"plugins": [
{ "transform": "@ttsc/strip", "configFile": "./config/strip.config.ts" }
]
}
}What “statement-level” means
The plugin only strips calls that are the entire statement:
console.log("debug"); // ← removed
const result = compute();
console.log(result); // ← removed
const data = console.log("x"); // ← NOT removed (the call is an expression)This is intentional, silently changing expressions can break code that depends on the call’s return value, however unusual that is.
Use cases
- Production builds: strip
console.loganddebugger, keepconsole.warnandconsole.error. - Test code in published artifacts: strip
assert.*from the package emit if your library usesnode:assertinternally. - Feature-flag tooling: wrap dev-only code in
metrics.devOnly(...)calls that get stripped in prod.
When not to use this
If you want a real minifier (dead-code elimination, mangling, …), use Terser or esbuild via @ttsc/unplugin. @ttsc/strip is the targeted “remove these specific patterns” pass.
See also
- @ttsc/banner: another emit-time plugin.
- @ttsc/paths: rewrite
compilerOptions.pathsaliases in the emit. - Plugin Development: write your own.