You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/rollup-plugin-babel/README.md
+22-15Lines changed: 22 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,35 +44,42 @@ All options are as per the [Babel documentation](https://babeljs.io/), except `o
44
44
Babel will respect `.babelrc` files – this is generally the best place to put your configuration.
45
45
46
46
47
-
## Babel 5
47
+
## Configuring Babel
48
48
49
-
The latest version of rollup-plugin-babel is designed to work with Babel 6. To use rollup-plugin-babel with Babel 5, install a 1.x version:
49
+
**The following applies to Babel 6 only. If you're using Babel 5, do `npm i -D rollup-plugin-babel@1`, as version 2 and above no longer supports Babel 5**
50
+
51
+
tl;dr: use the `es2015-rollup` preset instead of `es2015`.
50
52
51
53
```bash
52
-
npm install --save-dev rollup-plugin-babel@1
54
+
npm install --save-dev babel-preset-es2015-rollup
53
55
```
54
56
55
-
56
-
## Babel 6
57
-
58
-
With Babel 5, rollup-plugin-babel overrides the configuration to ensure that module syntax is left alone and that external helpers are collected for inclusion at the top of the bundle.
59
-
60
-
Babel 6 works differently – there's no `blacklist` or `externalHelpers` options. Instead of using the `es2015` preset, install and use [babel-preset-es2015-rollup](https://github.com/rollup/babel-preset-es2015-rollup):
61
-
62
57
```js
63
58
// .babelrc
64
59
{
65
60
"presets": [ "es2015-rollup" ]
66
61
}
67
62
```
68
63
69
-
If you're not using the preset, be sure to include the external helpers plugin:
64
+
### Modules
65
+
66
+
The `es2015` preset includes the [transform-es2015-modules-commonjs](http://babeljs.io/docs/plugins/transform-es2015-modules-commonjs/) plugin, which converts ES6 modules to CommonJS – preventing Rollup from working. Instead, you should either use the `es2015-rollup` preset, which excludes that plugin, or otherwise ensure that the `modules-commonjs` plugin is excluded. Rollup will throw an error if this is incorrectly configured.
67
+
68
+
### Helpers
69
+
70
+
In some cases Babel uses *helpers* to avoid repeating chunks of code – for example, if you use the `class` keyword, it will use a `classCallCheck` function to ensure that the class is instantiated correctly.
71
+
72
+
By default, those helpers will be inserted at the top of the file being transformed, which can lead to duplication. It's therefore recommended that you use the `external-helpers-2` plugin, which is automatically included in the `es2015-rollup` preset. Rollup will combine the helpers in a single block at the top of your bundle.
73
+
74
+
Alternatively, if you know what you're doing, you can use the `transform-runtime` plugin. If you do this, use `runtimeHelpers: true`:
varcheck=transform('export default class Foo {}',localOpts).code;
6
-
if(~check.indexOf('function _classCallCheck'))thrownewError('External helpers are not enabled. Please add the "external-helpers-2" plugin or use the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#TK for more information');
7
-
if(!~check.indexOf('export default'))thrownewError('It looks like your Babel configuration specifies a module transformer. Please disable it. If you\'re using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#TK for more information');
10
+
11
+
if(!~check.indexOf('export default')&&!~check.indexOf('export { Foo as default }'))thrownewError('It looks like your Babel configuration specifies a module transformer. Please disable it. If you\'re using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#TK for more information');
12
+
13
+
if(~check.indexOf('import _classCallCheck from "babel-runtime'))returnRUNTIME;
thrownewError('Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information');
67
+
}else{
68
+
usedHelpers.forEach(helper=>{
69
+
if(inlineHelpers[helper]){
70
+
warnOnce(`The '${helper} Babel helper is used more than once in your code. It's strongly recommended that you use the "external-helpers-2" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information`);
0 commit comments