# babel-plugin-transform-define

> Babel plugin that replaces member expressions and typeof statements with strings

Latest version **2.1.4** (published 2023-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-define
pnpm add babel-plugin-transform-define
yarn add babel-plugin-transform-define
bun add babel-plugin-transform-define
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: no vulnerabilities; has provenance.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2023-09-19 |
| First published | 2016-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.x.x |
| Dependencies | 2 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (Unknown) |
| GitHub stars | 242 |
| Maintainers | scottianstewart, keithluchtel, ceceppa, robwalkerco, gksander, sarahformidable, scott-rippey, michaelmerrill, sarmeyer, mariano-formidable, carlospaelinck, ryan.roemer, formidable-owner, eastridge, exogen, formidablelabs, carbonrobot, masiddee, mjackson |
| Keywords | babel-plugin, babel-transform, babel, define, DefinePlugin, webpack |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-define
- Repository: https://github.com/FormidableLabs/babel-plugin-transform-define
- Issues: https://github.com/FormidableLabs/babel-plugin-transform-define/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-define

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [traverse](https://npm.io/package/traverse.md) 0.6.6

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.1.4 (latest) — 2023-09-19
- 2.1.3 — 2023-07-27
- 2.1.2 — 2023-05-23
- 2.1.1 — 2023-05-15
- 2.1.0 — 2022-09-15
- 2.0.1 — 2021-09-10
- 2.0.0 — 2019-10-23
- 1.3.2 — 2019-10-22
- 1.3.1 — 2019-01-02
- 1.3.0 — 2017-05-23
- 1.2.0 — 2016-08-25
- 1.1.0 — 2016-08-19
- 1.0.1 — 2016-03-21
- 1.0.0 — 2016-03-21

## README

<a href="https://formidable.com/open-source/" target="_blank">
  <img alt="Babel Plugin Transform Define — Formidable, We build the modern web" src="https://raw.githubusercontent.com/FormidableLabs/babel-plugin-transform-define/master/babel-plugin-transform-define-Hero.png" />
</a>

<p align="center">
  <a title='Build Status' href="https://raw.githubusercontent.com/FormidableLabs/babel-plugin-transform-define/master/LICENSE">
    <img src='https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square' />
  </a>
  <a href="https://badge.fury.io/js/babel-plugin-transform-define">
    <img src="https://badge.fury.io/js/babel-plugin-transform-define.svg" alt="npm version" height="18">
  </a>
  <a href='https://github.com/FormidableLabs/babel-plugin-transform-define/actions'>
    <img src='https://github.com/FormidableLabs/babel-plugin-transform-define/workflows/CI/badge.svg' />
  </a>
  <a href='https://github.com/FormidableLabs/babel-plugin-transform-define#maintenance-status'>
    <img alt="Maintenance Status" src='https://img.shields.io/badge/maintenance-stable-yellow.svg?color=yellow&style=flat' />
  </a>
</p>

<h4 align="center">
  Compile time code replacement for babel similar to Webpack's <a href='https://webpack.js.org/plugins/define-plugin/'>DefinePlugin</a>
</h4>

***

## Quick Start

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

**.babelrc**

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

**.babelrc.js**

```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*
```json
{
  "plugins": [
    ["transform-define", {
      "VERSION": "1.0.0",
    }]
  ]
}
```

*Source Code*
```js
VERSION;

window.__MY_COMPANY__ = {
  version: VERSION
};
```

*Output Code*
```js
"1.0.0";

window.__MY_COMPANY__ = {
  version: "1.0.0"
};
```
***
##### `Member Expressions`

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

*Source Code*
```js
if (process.env.NODE_ENV === "production") {
  console.log(true);
}
```

*Output Code*
```js
if (true) {
  console.log(true);
}
```
***
##### `Unary Expressions`

*.babelrc*
```json
{
  "plugins": [
    ["transform-define", {
      "typeof window": "object"
    }]
  ]
}
```

*Source Code*
```js
typeof window;
typeof window === "object";
```

*Output Code*
```js
'object';
true;
```


***

## License

[MIT License](http://opensource.org/licenses/MIT)


## 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.

---
_Source: https://npm.io/package/babel-plugin-transform-define · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
