Update transform-es2015 READMEs from babel.github.io [skip ci] (#4926)

Signed-off-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
Brian Ng
2016-12-01 15:11:36 -06:00
committed by Henry Zhu
parent 723c90e8f0
commit f71efbce92
22 changed files with 469 additions and 21 deletions

View File

@@ -1,5 +1,25 @@
# babel-plugin-transform-es2015-modules-commonjs
> This plugin transforms ES2015 modules to [CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1).
## Example
**In**
```javascript
export default 42;
```
**Out**
```javascript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = 42;
```
## Installation
```sh
@@ -41,3 +61,27 @@ require("babel-core").transform("code", {
plugins: ["transform-es2015-modules-commonjs"]
});
```
## Options `loose`
As per the spec, `import` and `export` are only allowed to be used at the top
level. When in loose mode these are allowed to be used anywhere.
And by default, when using exports with babel a non-enumerable `__esModule` property
is exported.
```javascript
var foo = exports.foo = 5;
Object.defineProperty(exports, "__esModule", {
value: true
});
```
In environments that don't support this you can enable loose mode on `es6.modules`
and instead of using `Object.defineProperty` an assignment will be used instead.
```javascript
var foo = exports.foo = 5;
exports.__esModule = true;
```