diff --git a/bin/src/runRollup.js b/bin/src/runRollup.js index 45c305e..ff89f41 100644 --- a/bin/src/runRollup.js +++ b/bin/src/runRollup.js @@ -95,8 +95,15 @@ const equivalents = { }; function execute ( options, command ) { - let external = ( options.external || [] ) - .concat( command.external ? command.external.split( ',' ) : [] ); + let external = command.external ? + typeof options.external === 'function' ? + ((fn, a) => { + return function (id) { + return fn(id) || a.indexOf(id) !== -1; + }; + })(options.external, command.external.split(',')) : + (options.external || []).concat(command.external.split(',')) : + options.external; if ( command.globals ) { let globals = Object.create( null ); @@ -218,4 +225,4 @@ function bundle ( options ) { process.stdout.write( code ); }); -} +} \ No newline at end of file diff --git a/test/cli/config-external-function/_config.js b/test/cli/config-external-function/_config.js new file mode 100644 index 0000000..9f21d96 --- /dev/null +++ b/test/cli/config-external-function/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'external option gets passed from config', + command: 'rollup -c -e assert,external-module' +}; diff --git a/test/cli/config-external-function/_expected.js b/test/cli/config-external-function/_expected.js new file mode 100644 index 0000000..d760df4 --- /dev/null +++ b/test/cli/config-external-function/_expected.js @@ -0,0 +1,8 @@ +'use strict'; + +var ___config_js = require('./_config.js'); +var assert = require('assert'); +var externalModule = require('external-module'); + +assert.ok( ___config_js.execute ); +externalModule.method(); diff --git a/test/cli/config-external-function/main.js b/test/cli/config-external-function/main.js new file mode 100644 index 0000000..cfefa8c --- /dev/null +++ b/test/cli/config-external-function/main.js @@ -0,0 +1,6 @@ +import { execute } from './_config.js'; +import { ok } from 'assert'; +import { method } from 'external-module'; + +ok( execute ); +method(); diff --git a/test/cli/config-external-function/rollup.config.js b/test/cli/config-external-function/rollup.config.js new file mode 100644 index 0000000..ea45a3a --- /dev/null +++ b/test/cli/config-external-function/rollup.config.js @@ -0,0 +1,25 @@ +import assert from 'assert'; +import { resolve, sep } from 'path'; + +var config = resolve( './_config.js' ).split(sep).join('/'); + +export default { + entry: 'main.js', + format: 'cjs', + + external: function (id) { + if (id === config) { + return true; + } + + return false; + }, + + plugins: [ + { + load: function ( id ) { + assert.notEqual( id, config ); + } + } + ] +};