Skip to content

Latest commit

History

History
41 lines (32 loc) 路 550 Bytes

File metadata and controls

41 lines (32 loc) 路 550 Bytes

babel-plugin-typescript-enum-iife

Transform typescript wrapper enum in IIFE, enum better tree-shaking

Usage

babel-plugin-ts-enum-iife must be quoted first

bablerc.json

{
  "plugins": [
    "babel-plugin-ts-enum-iife",
    "@babel/plugin-transform-typescript"
  ]
}

enum

enum Test {
  A,
  B
}

output

const Test = function () {
  //__ENUM_IIFE__
  let Test;

  (function (Test) {
    Test[Test["A"] = 0] = "A";
    Test[Test["B"] = 1] = "B";
  })(Test || (Test = {}));

  return Test;
}();