Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #41 from joeldenning/external-helpers
Browse files Browse the repository at this point in the history
Adding support for referencing external, global helpers
  • Loading branch information
Victorystick committed Feb 23, 2016
2 parents a87fb97 + 0743932 commit e02dcdb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,6 +105,7 @@ export default function babel ( options ) {
};
},
intro () {
if ( externalHelpers ) return '';
const helpers = Object.keys( bundledHelpers );
if ( !helpers.length ) return '';

Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e02dcdb

Please sign in to comment.