[fix] babel-plugin option to rewrite to commonjs paths

Allow the babel plugin to be configured to rewrite paths to either ES
modules (default) or CommonJS.

Ref #961
This commit is contained in:
Nicolas Gallagher
2018-06-04 11:40:07 -07:00
parent e0f010da47
commit 026a92fd53
5 changed files with 84 additions and 14 deletions
@@ -17,10 +17,18 @@ yarn add --dev babel-plugin-react-native-web
```
{
"plugins": ["react-native-web"]
"plugins": [
["react-native-web", { commonjs: true }]
]
}
```
You should configure the plugin to match the module format used by your
bundler. Most modern bundlers will use a package's ES modules by default (i.e.,
if `package.json` has a `module` field). But if you need the plugin to rewrite
import paths to point to CommonJS modules, you must set the `commonjs` option
to `true`.
## Example
NOTE: `react-native-web` internal paths are _not stable_ and you must not rely