Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FormidableLabs/babel-plugin-transform-define
Compile time code replacement for babel similar to Webpack's DefinePlugin
https://github.com/FormidableLabs/babel-plugin-transform-define
Last synced: 3 months ago
JSON representation
Compile time code replacement for babel similar to Webpack's DefinePlugin
- Host: GitHub
- URL: https://github.com/FormidableLabs/babel-plugin-transform-define
- Owner: FormidableLabs
- License: mit
- Created: 2016-03-19T23:18:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-09-19T12:40:02.000Z (about 1 year ago)
- Last Synced: 2024-05-17T09:02:01.368Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.38 MB
- Stars: 246
- Watchers: 44
- Forks: 34
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Compile time code replacement for babel similar to Webpack's DefinePlugin***
## 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.