From 8d0ce825f933867a0626c47bd839d7d67e379b06 Mon Sep 17 00:00:00 2001 From: Tamas Hegedus Date: Sun, 16 Oct 2016 16:18:56 +0200 Subject: [PATCH 1/2] Added externalHelpersWhitelist option --- README.md | 6 +++++- src/index.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c64650..abfa451 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`, which gives explicit control over which babelHelper functions should be included in the bundle 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 f77a87f..f39ccb0 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,10 @@ 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; + return { name: 'babel', @@ -37,7 +41,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( ', ')} }`; From 8b61cfb8a355041ad370bad21347051a1429368d Mon Sep 17 00:00:00 2001 From: Tamas Hegedus Date: Sun, 16 Oct 2016 17:03:50 +0200 Subject: [PATCH 2/2] Improve options description in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index abfa451..6fc943b 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ rollup({ 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`, which gives explicit control over which babelHelper functions should be included in the bundle + * `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.