move some babel-plugins into the main repo
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
*.log
|
||||
src
|
||||
35
packages/babel-plugin-inline-environment-variables/README.md
Normal file
35
packages/babel-plugin-inline-environment-variables/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# babel-plugin-inline-environment-variables
|
||||
|
||||
Inline environment variables
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install babel-plugin-inline-environment-variables
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["inline-environment-variables"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
$ babel --plugins inline-environment-variables script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["inline-environment-variables"]
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "babel-plugin-inline-environment-variables",
|
||||
"version": "1.0.1",
|
||||
"description": "Inline environment variables",
|
||||
"repository": "babel-plugins/babel-plugin-inline-environment-variables",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export default function ({ Plugin, types: t }) {
|
||||
return new Plugin("inline-environment-variables", {
|
||||
metadata: {
|
||||
group: "builtin-pre"
|
||||
},
|
||||
|
||||
visitor: {
|
||||
MemberExpression(node) {
|
||||
if (this.get("object").matchesPattern("process.env")) {
|
||||
var key = this.toComputedKey();
|
||||
if (t.isLiteral(key)) {
|
||||
return t.valueToNode(process.env[key.value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user