Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/discord/babel-plugin-define-patterns

Create constants that replace various expressions at build-time
https://github.com/discord/babel-plugin-define-patterns

babel babel-plugin loader webpack webpack-loader

Last synced: about 1 month ago
JSON representation

Create constants that replace various expressions at build-time

Awesome Lists containing this project

README

        

# babel-plugin-define-patterns

> Create constants that replace various expressions at build-time

## Install

```sh
npm install --save-dev babel-plugin-define-patterns
```

## Usage

```js
// babel.config.json
{
"plugins": [
["define-patterns", {
"replacements": {
"process.env.NODE_ENV": "production",
"typeof window": "object",
"__DEV__": true,
"require('currentBuildNumber')": 42
}
}]
]
}
```

## Example

**Input:**

```js
process.env.NODE_ENV
```

**Options:**

```json
{
"replacements": {
"process.env.NODE_ENV": "development"
}
}
```

**Output:**

```js
"development"
```

For more examples see [input.txt](./fixtures/input.txt) and
[output.txt](./fixtures/output.txt).