add more plugins, rename some

This commit is contained in:
Sebastian McKenzie
2015-09-15 06:12:46 +01:00
parent 3e8cbc60eb
commit 9969224a93
328 changed files with 2013 additions and 1543 deletions

View File

@@ -0,0 +1,3 @@
node_modules
*.log
src

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

View 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"]
});
```

View 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"
]
}

View 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));
}
}
}
}
}
};
}