babel-plugin-minify-mangle-names

Example

In

  1. var globalVariableName = 42;
  2. function foo() {
  3. var longLocalVariableName = 1;
  4. if (longLocalVariableName) {
  5. console.log(longLocalVariableName);
  6. }
  7. }

Out

  1. var globalVariableName = 42;
  2. function foo() {
  3. var a = 1;
  4. if (a) {
  5. console.log(a);
  6. }
  7. }

Installation

  1. npm install babel-plugin-minify-mangle-names --save-dev

Usage

  1. // without options
  2. {
  3. "plugins": ["minify-mangle-names"]
  4. }
  1. // with options
  2. {
  3. "plugins": [
  4. ["minify-mangle-names", { "exclude": { "foo": true, "bar": true} }]
  5. ]
  6. }

Via CLI

  1. babel --plugins minify-mangle-names script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["minify-mangle-names"]
  3. });

Options

  • exclude - A plain JS Object with keys as identifier names and values indicating whether to exclude (default: {})
  • eval - mangle identifiers in scopes accessible by eval (default: false)
  • keepFnName - prevent mangler from altering function names. Useful for code depending on fn.name (default: false)
  • topLevel - mangle topLevel Identifiers (default: false)
  • keepClassName - prevent mangler from altering class names (default: false).

You can read more about configuring plugin options here