Registry / devops / es6-class-minify

es6-class-minify

JSON →
library4.0.0jsnpmunverified

A specialized minifier for ES6 class fields and member functions, currently at version 4.0.0. Standard JavaScript minifiers cannot rename class properties or methods without breaking runtime behavior because they cannot track object instances. This package works around that by automatically renaming any property or method starting with underscore (`_`), which is a safe convention not used by built-in JavaScript names. It is meant to be used alongside a general-purpose minifier (like terser) to achieve complete code minification. The package has a Node.js engine requirement of >=13 and has no dependencies.

npm install es6-class-minify
INSTALL
IMPORT
SIG · ES6-CLASS-MINIFY
E
es6-class-minify
devopsjavascriptv4.0.0
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.

ES6ClassMinify
import { ES6ClassMinify } from 'es6-class-minify'
const ES6ClassMinify = require('es6-class-minify')
The package only exports a named export, not a default. CommonJS require() works but needs destructuring.
ClassMinifierOptions
import type { ClassMinifierOptions } from 'es6-class-minify'
TypeScript users can import the options type for the constructor. Not available in CJS.
ES6ClassMinify (type)
import type { ES6ClassMinify } from 'es6-class-minify'
import { ES6ClassMinify } from 'es6-class-minify' // in TypeScript, use import type for type-only
When using TypeScript and wanting to refer to the class type, use import type to avoid runtime import.

Demonstrates how to import, create an instance, and minify a class that uses underscore-prefixed properties.

import { ES6ClassMinify } from 'es6-class-minify'; const code = ` class Counter { _count = 0; _plus() { this._count++; } _get() { return this._count; } } const counter = new Counter(); counter._plus(); console.log(counter._get()); `; const minifier = new ES6ClassMinify(); const minified = minifier.minify(code); console.log(minified); // Output: class Counter { a = 0; b() { this.a++; } c() { return this.a; } } ...
Debug
Known issues
gotchaOnly properties and methods prefixed with underscore (_) are minified. Any other properties or methods are left unchanged.
fix
Ensure all class members you want minified start with an underscore. Alternatively, use new ClassMinifierOptions with a custom prefix.
affects: >=4.0.0
gotchaThe minifier does not detect or avoid name collisions with other variables. If two classes have members starting with underscore, they may be renamed to the same short name.
fix
Minify each file separately or ensure class file boundaries are isolated. No built-in collision detection.
affects: >=4.0.0
gotchaDoes not minify class names, function names outside methods, or regular variable names. This is intentional: use with another minifier.
fix
Chain this package with a general minifier like terser for complete minification.
affects: >=4.0.0
Errors
Common errors & fixes
ES6ClassMinify is not a constructor
Incorrect import: using default import instead of named import.
fix
Use import { ES6ClassMinify } from 'es6-class-minify'.
Cannot find module 'es6-class-minify'
Package not installed or incorrect path.
fix
Run npm install es6-class-minify and ensure node_modules is correct.
TypeError: minifier.minify is not a function
ES6ClassMinify imported as a type or wrong class instance.
fix
Instantiate with new ES6ClassMinify() before calling .minify().
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
es6-class-minify — npm install es6-class-minify · libregistry