diff --git a/README.md b/README.md index 4695439..050377f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,11 @@ rollup({ }).then(...) ``` -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). +All options are as per the [Babel documentation](https://babeljs.io/), except the following: + + * `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) + * `options.externalHelpersWhitelist`: an array which gives explicit control over which babelHelper functions are allowed in the bundle (by default, every helper is allowed) Babel will respect `.babelrc` files – this is generally the best place to put your configuration. diff --git a/src/index.js b/src/index.js index 864f022..f93572f 100644 --- a/src/index.js +++ b/src/index.js @@ -26,8 +26,12 @@ export default function babel ( options ) { if ( options.externalHelpers ) externalHelpers = true; delete options.externalHelpers; + let externalHelpersWhitelist = null; + if ( options.externalHelpersWhitelist ) externalHelpersWhitelist = options.externalHelpersWhitelist; + delete options.externalHelpersWhitelist; + let warn = msg => console.warn(msg); // eslint-disable-line no-console - + return { name: 'babel', @@ -43,7 +47,7 @@ export default function babel ( options ) { if ( id === HELPERS ) { const pattern = new RegExp( `babelHelpers\\.(${keywordHelpers.join('|')})`, 'g' ); - const helpers = buildExternalHelpers( null, 'var' ) + const helpers = buildExternalHelpers( externalHelpersWhitelist, 'var' ) .replace( pattern, 'var _$1' ) .replace( /^babelHelpers\./gm, 'export var ' ) + `\n\nexport { ${keywordHelpers.map( word => `_${word} as ${word}`).join( ', ')} }`;