2.1.4 • Published 6 months ago

babel-plugin-transform-define v2.1.4

Weekly downloads
861,999
License
MIT
Repository
github
Last release
6 months ago

Quick Start

$ npm install --save-dev babel-plugin-transform-define

.babelrc

{
  "plugins": [
    ["transform-define", {
      "process.env.NODE_ENV": "production",
      "typeof window": "object"
    }]
  ]
}

.babelrc.js

// E.g., any dynamic logic with JS, environment variables, etc.
const overrides = require("./another-path.js");

module.exports = {
  plugins: [
    ["transform-define", {
      "process.env.NODE_ENV": "production",
      "typeof window": "object",
      ...overrides
    }]
  ]
};

Reference Documentation

babel-plugin-transform-define can transform certain types of code as a babel transformation.

Identifiers

.babelrc

{
  "plugins": [
    ["transform-define", {
      "VERSION": "1.0.0",
    }]
  ]
}

Source Code

VERSION;

window.__MY_COMPANY__ = {
  version: VERSION
};

Output Code

"1.0.0";

window.__MY_COMPANY__ = {
  version: "1.0.0"
};

Member Expressions

.babelrc

{
  "plugins": [
    ["transform-define", {
      "process.env.NODE_ENV": "production"
    }]
  ]
}

Source Code

if (process.env.NODE_ENV === "production") {
  console.log(true);
}

Output Code

if (true) {
  console.log(true);
}

Unary Expressions

.babelrc

{
  "plugins": [
    ["transform-define", {
      "typeof window": "object"
    }]
  ]
}

Source Code

typeof window;
typeof window === "object";

Output Code

'object';
true;

License

MIT License

Maintenance Status

Stable: Formidable is not planning to develop any new features for this project. We are still responding to bug reports and security concerns. We are still welcoming PRs for this project, but PRs that include new features should be small and easy to integrate and should not include breaking changes.

@jetbrains/ring-uiaerolito-next@sirius-black/taro-clinext-sheertex@hai5/react-navigationsxyj_taro_clisxyj-taro-transformer-wx@cyca/babel-preset@cyca/babel-presets@everything-registry/sub-chunk-1204hx-react-navigationkms-web-configguestline-scriptslastjslayout-nextjs2jdseal-climonkey-coremonkenext10-clinext-web-configmsupmoleculer-lambda-gatewaymoleculer-nextjsmps-clijsx2mp-loadernext-but-onenext-devdepnext-react-app-scriptsmediastoresdk-iwonagm-react-navigationfast-tscfabuildfatherfastscexpress-engine-inferno-jsxforked-next-project-to-fix-app-engineone-svg-toolreact-navigation-latestreact-navigation-dgjoyreact-navigation-fiexedreact-navigation-fixedreact-navigation-forkpaulpn-ui-kitrazzlepika-plugin-bundle-umdpika-plugin-legacy-browserrugalremote-modulesserverless-fuck-you-4kb@dymp/dylphin-cli@elzzad/dazzle-babel-loader@ericmcornelius/ease@grund/babel-preset@gtarojs/cli@fangchan/taro-cli@hyext/builder-beyond@hyext/builder-h5game@hyext/builder-webview@ijjk/next@infinitebrahmanuniverse/nolb-babel-plugin-ttso-react-navigationun-processing-centeruber-nexttracing-nextdp-taro-transformer-wxdp-taro-clidp-taro-mini-runner@mhhegazy/next@jonny/react-navigation@mini_program/cli@module-federation/next@modern-js/babel-preset-libtudou@neat-preset/babel@maa/monkey@hitorisensei/nextwxmp-transformer-jsx@gift-adv/taro-cli@d-bigfish/cli@digiforce-cloud/build-plugin-component@dosvit/app-framework@dayuw/tarojs-clistyled-starterstrikingly-taro-clisw-nexttaro-externalclass-plugintarojs-clitarojs-mini-runnersps-cli@c-art/clitest-machine-webpacktbhag-nextbuild-plugin-one-code-for-componentsbuild-plugin-componentsl-react-navigationserverless-moleculerredbud@mooyoojs/taro-rax-cli@nore/plugin-js@pinweb/cli
2.1.4

6 months ago

2.1.3

8 months ago

2.1.2

10 months ago

2.1.1

11 months ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

4 years ago

1.3.2

4 years ago

1.3.1

5 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago