babel-plugin-transform-define

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

  • 所有者: FormidableLabs/babel-plugin-transform-define
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖


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

主要指標

概覽
名稱與所有者FormidableLabs/babel-plugin-transform-define
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-03-19 23:18:20
推送於2024-12-19 17:56:28
最后一次提交2024-12-19 12:56:26
發布數15
最新版本名稱v2.1.4 (發布於 2023-09-19 12:40:01)
第一版名稱latest (發布於 )
用户参与
星數245
關注者數43
派生數31
提交數134
已啟用問題?
問題數15
打開的問題數3
拉請求數60
打開的拉請求數4
關閉的拉請求數12
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?