4.0.0 • Published 3 years ago

es6-class-minify v4.0.0

Weekly downloads
6
License
Unlicense
Repository
github
Last release
3 years ago

es6-class-minify

Package to minify ES6 classes and objects.

Current minifiers cannot minify ES6 class fields and member functions. This is because they are not able to track the class when a method is called on an object.

This package provides a simple way to minify class fields and members by manually prefixing the name with a _. This package will rename all fields and members in a class and all corresponding accesses on an object. This package does not need to track which object is an instance of which class, because it can simply rename all usages of a field or method prefixed by _. The standard JavaScript definitions do not include such names, so built-in names are never accidentally minified.

Installation

npm install es6-class-minify

Usage

Single file:

import { ES6ClassMinify } from "es6-class-minify";

const es6ClassMinify = new ES6ClassMinify();
es6ClassMinify.minify("...");

Example

Plain code:

class Counter {
  _count = 0;

  _plus() {
    this._count++;
  }

  _get() {
    return this._count;
  }
}

const counter = new Counter();
counter._plus();
counter._plus();
console.log(counter._get());

Minified code:

class Counter {
  a = 0;

  b() {
    this.a++;
  }

  c() {
    return this.a;
  }
}

const counter = new Counter();
counter.b();
counter.b();
console.log(counter.c());

All class members and fields are minified. Other variables are not minified, since there are already very good minifiers for those things. You should use this package in addition to another classical minifier.

4.0.0

3 years ago

3.1.0

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago