add more plugins, rename some
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
*.log
|
||||
src
|
||||
22
packages/babel-plugin-transform-node-env-inline/LICENSE
Normal file
22
packages/babel-plugin-transform-node-env-inline/LICENSE
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2015 Sebastian McKenzie <sebmck@gmail.com>
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
56
packages/babel-plugin-transform-node-env-inline/README.md
Normal file
56
packages/babel-plugin-transform-node-env-inline/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# babel-plugin-transform-node-env-inline
|
||||
|
||||
Inline the `NODE_ENV` environment variable and if it's a part of a binary expression
|
||||
(eg. `process.env.NODE_ENV === "development"`) then statically evaluate and replace it.
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
process.env.NODE_ENV === "development";
|
||||
process.env.NODE_ENV === "production";
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```sh
|
||||
$ NODE_ENV=development babel in.js --plugins transform-node-env-inline
|
||||
```
|
||||
|
||||
```javascript
|
||||
true;
|
||||
false;
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install babel-plugin-transform-node-env-inline
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-node-env-inline"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
$ babel --plugins transform-node-env-inline script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["transform-node-env-inline"]
|
||||
});
|
||||
```
|
||||
11
packages/babel-plugin-transform-node-env-inline/package.json
Normal file
11
packages/babel-plugin-transform-node-env-inline/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "babel-plugin-transform-node-env-inline",
|
||||
"version": "1.0.1",
|
||||
"description": "",
|
||||
"repository": "babel/babel",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
]
|
||||
}
|
||||
18
packages/babel-plugin-transform-node-env-inline/src/index.js
Normal file
18
packages/babel-plugin-transform-node-env-inline/src/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
MemberExpression(path) {
|
||||
if (path.matchesPattern("process.env.NODE_ENV")) {
|
||||
path.replaceWith(t.valueToNode(process.env.NODE_ENV));
|
||||
|
||||
if (path.parentPath.isBinaryExpression()) {
|
||||
var evaluated = path.parentPath.evaluate();
|
||||
if (evaluated.confident) {
|
||||
path.parentPath.replaceWith(t.valueToNode(evaluated.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user