Skip to Content

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.log
  • console.debug
  • assert.*
  • 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.* matches assert.equal, assert.deepStrictEqual, …).
  • statements: bare statements. Currently supports debugger.

@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.log and debugger, keep console.warn and console.error.
  • Test code in published artifacts: strip assert.* from the package emit if your library uses node:assert internally.
  • 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

Last updated on