Registry / devops / tsminifier

tsminifier

JSON →
library4.1.0-dev.1jsnpmunverified

TsMinifier is a TypeScript minifier that provides identifier mangling and whitespace removal, targeting TypeScript source files directly. Version 4.1.0-dev.1 is a development release. It differs from general minifiers by operating on TypeScript syntax rather than transpiled JavaScript, and it integrates as a transform plugin for the ts2js compiler. The package ships TypeScript type definitions. It has a small focus compared to full-featured minifiers like Terser, but offers simplicity for TypeScript-specific minification.

npm install tsminifier
INSTALL
IMPORT
SIG · TSMINIFIER
T
tsminifier
devopsjavascriptv4.1.0-dev.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
import { minify } from 'tsminifier'
Named export for the main minify function.
MinifyOptions
import { MinifyOptions } from 'tsminifier'
import MinifyOptions from 'tsminifier'
Type export, not default.
default
import TsMinifier from 'tsminifier'
const TsMinifier = require('tsminifier').default
Package has a default export (the class/function) but named exports are preferred. In CommonJS, use require('tsminifier').default.

Demonstrates basic usage of the minify function to minify a TypeScript file with identifier mangling and whitespace removal.

import { minify } from 'tsminifier'; import { readFileSync, writeFileSync } from 'fs'; const code = readFileSync('input.ts', 'utf8'); const result = minify(code, { mangleIdentifiers: true, removeWhitespace: true }); if (result.error) { console.error('Minification error:', result.error); } else { writeFileSync('output.ts', result.code, 'utf8'); }
Debug
Known issues
breakingIn version 4.0.0, the minify function signature changed; it no longer accepts a string as first argument without options object.
fix
Update calls to pass an options object as the second argument: minify(code, { mangleIdentifiers: true })
affects: >=4.0.0 <4.1.0
deprecatedThe 'transform' export used for ts2js plugin is deprecated since version 3.5.0.
fix
Use the new plugin system via '@toddthomson/ts2js-transform-minify' instead.
affects: >=3.5.0 <4.0.0
gotchaIdentifier mangling can break TypeScript code that relies on string-based property access (e.g., obj['property']) or Reflect calls.
fix
Set mangleIdentifiers: false or use a reserved property list.
affects: >=1.0.0
deprecatedThe package's main entry point changed from 'index.js' to 'dist/index.js' in version 3.0.0.
fix
Ensure your import path references 'tsminifier' not 'tsminifier/index.js'.
affects: >=3.0.0 <4.0.0
gotchaThe minifier outputs TypeScript code, not JavaScript. It does not transpile TypeScript to JavaScript.
fix
Use a separate TypeScript compiler (e.g., tsc) after minification if you need JavaScript output.
affects: >=1.0.0
breakingVersion 2.0.0 removed support for Node.js versions below 8.
fix
Upgrade Node.js to version 14 or above as per current requirements.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: tsminifier.minify is not a function
Importing the package incorrectly (e.g., default import when named export needed).
fix
Use named import: import { minify } from 'tsminifier'
Cannot find module 'tsminifier'
Package not installed or incorrect import path.
fix
Run: npm install tsminifier@latest
SyntaxError: Unexpected token in TypeScript source
The input contains unsupported TypeScript syntax (e.g., decorators, JSX).
fix
Transpile to ES2015+ first or avoid using unsupported syntax.
error TS2300: Duplicate identifier 'x'
Identifier mangling created conflicting names in the same scope.
fix
Set mangleIdentifiers: false or increase the mangling scope.
Upgrade
Version history
4.1.0-dev.1latest on npm
Audit
Dependencies
typescriptoptionalRequired for parsing and manipulating TypeScript AST; the minifier works directly on TypeScript syntax.
Agent activity
2 hits · last 30 days
node
2
Resources
tsminifier — npm install tsminifier · libregistry