MCPcopy Index your code
hub / github.com/FormidableLabs/babel-plugin-transform-define

github.com/FormidableLabs/babel-plugin-transform-define @v2.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1.4 ↗ · + Follow
18 symbols 29 edges 27 files 0 documented · 0% 14 cross-repo links updated 18mo agov2.1.4 · 2023-09-19★ 2433 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Babel Plugin Transform Define — Formidable, We build the modern web

npm version Maintenance Status

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


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.

Core symbols most depended-on inside this repo

assertTransform
called by 13
test/index.js
getBabelOps
called by 12
test/index.js
processNode
called by 3
lib/index.js
splitLines
called by 3
test/index.js
_defineProperty
called by 3
test/object-keys-properties/expected.js
replaceAndEvaluateNode
called by 1
lib/index.js
isImportIdentifier
called by 1
lib/index.js
memberExpressionComparator
called by 0
lib/index.js

Shape

Function 18

Languages

TypeScript100%

Modules by API surface

lib/index.js10 symbols
test/index.js3 symbols
test/object-keys-properties/expected.js1 symbols
test/import-identifiers/expected.js1 symbols
test/import-identifiers/actual.js1 symbols
test/binding/expected.js1 symbols
test/binding/actual.js1 symbols

For agents

$ claude mcp add babel-plugin-transform-define \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact