node package manager

babel-plugin-minprops

minprops

Normally, a JavaScript minifier will not minify object properties, because they may be used elsewhere, in files other than the one in which they are defined. Minify allows you to write descriptive property names and safely minify them for production builds.

Example

Without minprops:

foo.js

class Foo {
  callTheFunctionWithTheArgsThatWerePassed(fn, ...args) {
    return fn(...args);
  }
}
 
module.exports = Foo;

index.js

const Foo = require('./foo');
 
Foo.callTheFunctionWithTheArgsThatWerePassed((num1, num2) => num1 + num2, 1, 2);

⭆⭆⭆ MINIFY! ⇒⇒⇒

foo.min.js

class a {
  callTheFunctionWithTheArgsThatWerePassed(b, ...c) {
    return b(...c);
  }
}
 
module.exports = a;

index.min.js

const a = require('./foo');
 
a.callTheFunctionWithTheArgsThatWerePassed((b, c) => b + c, 1, 2);

With minprops:

Use $__ to notate properties that are private to the package and can be safely renamed.

foo.js

class Foo {
  $__callTheFunctionWithTheArgsThatWerePassed(fn, ...args) {
    return fn(...args);
  }
}
 
module.exports = Foo;

index.js

const Foo = require('./foo');
 
Foo.$__callTheFunctionWithTheArgsThatWerePassed((num1, num2) => num1 + num2, 1, 2);

⭆⭆⭆ MINIFY! ⇒⇒⇒

foo.min.js

class a {
  a(b, ...c) {
    return b(...c);
  }
}
 
module.exports = a;

index.min.js

const a = require('./foo');
 
a.a((b, c) => b + c, 1, 2);

Options

Options can be specified in a minprops property in your package.json

{
  ...
  "minprops": {
    "exclude": [
      "id"
    ],
    "matchPrefix": "$__"
  }
  ...
}
  • exclude: List an array of properties to not minify to. Use this if your package has properties that are two characters or less.
  • matchPrefix: Use a custom prefix. Defaults to $__.