Strip debug code
ttsc is the standalone TypeScript-Go compiler — see Setup if you haven’t installed it yet.
@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
{
"compilerOptions": {
"plugins": [
{
"transform": "@ttsc/strip",
"calls": ["logger.debug", "metrics.devOnly", "assert.*"],
"statements": ["debugger"]
}
]
}
}calls— statement-level calls. Supports a.\*wildcard at the end (e.g.assert.*matchesassert.equal,assert.deepStrictEqual, …).statements— bare statements. Currently supportsdebugger.
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
- Plugins — the plugin index.
- @ttsc/banner — another emit-time plugin.
- Plugin Development — write your own.
Last updated on