Skip to content

Commit

Permalink
Add docs for strict and noInterop with es2015-modules-commonjs.
Browse files Browse the repository at this point in the history
(cherry picked from commit 23de276)
  • Loading branch information
rwjblue authored and existentialism committed May 19, 2017
1 parent 0abc86f commit 6ba4c2e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-es2015-modules-amd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ require("babel-core").transform("code", {
plugins: ["transform-es2015-modules-amd"]
});
```

### Options

See options for `babel-plugin-transform-es2015-commonjs`.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,53 @@ Object.defineProperty(exports, "__esModule", {
});
```

In environments that don't support this you can enable loose mode on `es6.modules`
In environments that don't support this you can enable loose mode on `babel-plugin-transform-es20150-modules-commonjs`
and instead of using `Object.defineProperty` an assignment will be used instead.

```javascript
var foo = exports.foo = 5;
exports.__esModule = true;
```

### `strict`

`boolean`, defaults to `false`

By default, when using exports with babel a non-enumerable `__esModule` property
is exported. In some cases this property is used to determine if the import _is_ the
default export or if it _contains_ the default export.

```javascript
var foo = exports.foo = 5;

Object.defineProperty(exports, "__esModule", {
value: true
});
```

In order to prevent the `__esModule` property from being exported, you can set
the `strict` option to `true`.

### `noInterop`

`boolean`, defaults to `false`

By default, when using exports with babel a non-enumerable `__esModule` property
is exported. This property is then used to determine if the import _is_ the default
export or if it _contains_ the default export.

```javascript
"use strict";

var _foo = require("foo");

var _foo2 = _interopRequireDefault(_foo);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
```

In cases where the auto-unwrapping of `default` is not needed, you can set the
`noInterop` option to `true` to avoid the usage of the `interopRequireDefault`
helper (shown in inline form above).

0 comments on commit 6ba4c2e

Please sign in to comment.