@applications-developer/babel-plugin-transform-define
@applications-developer/babel-plugin-transform-define
npm i @applications-developer/babel-plugin-transform-define
@applications-developer/babel-plugin-transform-define

@applications-developer/babel-plugin-transform-define

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

by FormidableLabs

1.3.1 (see all)License:MITTypeScript:Not Found
npm i @applications-developer/babel-plugin-transform-define
Readme

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

Downloads/wk

4

GitHub Stars

246

LAST COMMIT

9mos ago

MAINTAINERS

1

CONTRIBUTORS

14

OPEN ISSUES

2

OPEN PRs

2
VersionTagPublished
1.3.1
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate