Socket
Socket
Sign inDemoInstall

babel-plugin-transform-define

Package Overview
Dependencies
2
Maintainers
21
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-define

Babel plugin that replaces member expressions and typeof statements with strings


Version published
Maintainers
21
Install size
1.41 MB
Created

Changelog

Source

1.3.0 (2017-05-15)

User Facing Changes
  • Support falsy replacement values [https://github.com/FormidableLabs/babel-plugin-transform-define/pull/33]
Internal
  • Update eslint config and packages
  • Update lodash version

Readme

Source

babel-plugin-transform-define

npm version

Compile time code replacement for babel similar to Webpack's DefinePlugin

Quick Start

npm install babel-plugin-transform-define

.babelrc

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

.babelrc

{
  "plugins": [
    ["transform-define", "./path/to/config/file.js"]
  ]
}

Note: Paths are relative to `process.cwd()``

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

Keywords

FAQs

Last updated on 23 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc