decomment is a CLI tool to safely remove comments from JavaScript, TypeScript, JSX, TSX, and Vue files.
It performs AST-based comment removal to ensure code behavior is never changed. The tool is designed for production codebases, CI pipelines, and teams that care about safety, auditability, and reversibility.
Remove comments β and nothing else.
//) and block (/* */) commentseslint-, @license)decomment.config.jsnpm install -g @tomatobybike/decomment
or
yarn global add @tomatobybike/decomment --ignore-engines
Yarn v1 global install is not recommended due to legacy dependency constraints.
yarn add @tomatobybike/decomment
# Remove comments
decomment [options] [files/globs]
# Restore files from backups
decomment restore
# Remove all backup files
decomment clean
If no files or globs are provided, decomment scans the current directory by default.
| Option | Description |
|---|---|
--dry-run |
Preview changes without writing files |
--keep |
Comma-separated comment prefixes to preserve |
--stats |
Show number of comments removed and kept |
-h, --help |
Show help message |
Default preserved prefixes:
eslint-, @license, @preserve
decomment
Equivalent to:
decomment "**/*.{js,mjs,jsx,tsx,vue}"
Automatically excludes:
node_modulesdistbuild.gitdecomment "src/**/*.js" --dry-run --stats
decomment "src/**/*.{js,mjs,jsx,tsx,vue}" --stats
decomment "src/**/*.{js,ts}" --keep eslint-,@license --stats
decomment.config.js)An optional configuration file can be placed at the project root.
export default {
include: ["src/**/*.{js,mjs,jsx,tsx,vue}", "test/**/*.{js,mjs,jsx,tsx,vue}"],
keep: ["eslint-", "@license", "@preserve"],
};
config.include**/*.{js,mjs,jsx,tsx,vue})For each processed file, decomment creates a single backup:
<file>.decomment.bak
decomment restore
Restores files from their .decomment.bak backups.
decomment clean
Deletes all .decomment.bak files in the matched scope.
| Feature / Tool | decomment | strip-comments | comment-strip | Babel / esbuild / Terser |
|---|---|---|---|---|
| AST-based (safe) | β Yes | β Regex-based | β Regex-based | β Yes |
| Preserves semantics | β Guaranteed | β Risky | β Risky | β Not guaranteed |
| Removes only comments | β Yes | β οΈ Mostly | β οΈ Mostly | β No (build output) |
| JSX / TSX support | β Yes | β οΈ Partial | β οΈ Partial | β Yes |
| Vue SFC support | β Script section only | β No | β No | β οΈ Limited |
| Preserve prefixes | β
Yes (--keep) |
β No | β No | β οΈ Limited |
| Dry-run mode | β Yes | β No | β No | β No |
| Statistics output | β Yes | β No | β No | β No |
| Backup & rollback | β Yes | β No | β No | β No |
| Glob batch processing | β Yes | β οΈ Limited | β οΈ Limited | β οΈ Build-specific |
| Config file support | β Yes | β No | β No | β No |
| CI / pre-commit ready | β Designed for it | β No | β No | β οΈ Not intended |
| Risk of breaking code | Very Low | Medium | Medium | High |
| Primary use case | Production codebase hygiene | Small scripts | Small scripts | Build & minification |
If you care about safety, reviewability, and deterministic output, this tool is built for you.
decomment is designed to work naturally with npm scripts for safe and repeatable workflows.
{
"scripts": {
"decomment": "decomment",
"decomment:check": "decomment --dry-run --stats",
"decomment:fix": "decomment --stats",
"decomment:restore": "decomment restore",
"decomment:clean": "decomment clean"
}
}
# Preview comment removal (no file changes)
npm run decomment:check
# Remove comments and create backups
npm run decomment:fix
# Restore all files from backups
npm run decomment:restore
# Remove all .decomment.bak files
npm run decomment:clean
You can integrate decomment into a pre-commit workflow to automatically remove comments before each commit.
β οΈ This is optional and recommended only for teams that already use Husky.
npm install -D husky
npx husky install
npx husky add .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
echo "π§Ή Running decomment..."
npx decomment "src/**/*.{js,mjs,jsx,tsx,vue}" \
--keep eslint-,@license,@preserve \
--stats
MIT License