diff --git a/packages/rollup-plugin-babel/README.md b/packages/rollup-plugin-babel/README.md index 7e487723f..d43625742 100644 --- a/packages/rollup-plugin-babel/README.md +++ b/packages/rollup-plugin-babel/README.md @@ -39,7 +39,7 @@ rollup({ }).then(...) ``` -All options are as per the [Babel documentation](https://babeljs.io/), except `options.include` and `options.exclude` (each a minimatch pattern, or array of minimatch patterns), which determine which files are transpiled by Babel (by default, all files are transpiled). +All options are as per the [Babel documentation](https://babeljs.io/), except `options.externalHelpers` (a boolean value indicating whether to bundle in the babel helpers), `options.include` and `options.exclude` (each a minimatch pattern, or array of minimatch patterns), which determine which files are transpiled by Babel (by default, all files are transpiled). Babel will respect `.babelrc` files – this is generally the best place to put your configuration. @@ -90,6 +90,19 @@ rollup.rollup({ }).then(...) ``` +Finally, if you do not wish the babel helpers to be included in your bundle at all (but instead reference the global `babelHelpers` object), you may set the `externalHelpers` option to `true`: + +```js +rollup.rollup({ + ..., + plugins: [ + babel({ + plugins: ['external-helpers-2'], + externalHelpers: true + }) + ] +}).then(...) +``` ## License diff --git a/packages/rollup-plugin-babel/src/index.js b/packages/rollup-plugin-babel/src/index.js index dc27ac9e2..8411e2e1f 100644 --- a/packages/rollup-plugin-babel/src/index.js +++ b/packages/rollup-plugin-babel/src/index.js @@ -67,6 +67,10 @@ export default function babel ( options ) { const runtimeHelpers = options.runtimeHelpers; delete options.runtimeHelpers; + var externalHelpers; + if ( options.externalHelpers ) externalHelpers = true; + delete options.externalHelpers; + return { transform ( code, id ) { if ( !filter( id ) ) return null; @@ -101,6 +105,7 @@ export default function babel ( options ) { }; }, intro () { + if ( externalHelpers ) return ''; const helpers = Object.keys( bundledHelpers ); if ( !helpers.length ) return ''; diff --git a/packages/rollup-plugin-babel/test/test.js b/packages/rollup-plugin-babel/test/test.js index fa66cf8d3..59a380c9e 100644 --- a/packages/rollup-plugin-babel/test/test.js +++ b/packages/rollup-plugin-babel/test/test.js @@ -71,6 +71,19 @@ describe( 'rollup-plugin-babel', function () { }); }); + it( 'does not add helpers when externalHelpers option is truthy', function () { + return rollup.rollup({ + entry: 'samples/class/main.js', + plugins: [ babelPlugin({externalHelpers: true}) ] + }).then( function ( bundle ) { + var generated = bundle.generate(); + var code = generated.code; + + assert.ok( code.indexOf( 'babelHelpers =' ) === -1, generated.code ); + assert.ok( code.indexOf( 'babelHelpers.classCallCheck =' ) === -1, generated.code ); + }); + }); + it( 'does not babelify excluded code', function () { return rollup.rollup({ entry: 'samples/exclusions/main.js',