Browse Source

allow --globals to work with --external and options.external in whatever configuration (#743)

semi-dynamic-namespace-imports
Rich-Harris 9 years ago
parent
commit
03ed02c0f6
  1. 25
      bin/src/runRollup.js

25
bin/src/runRollup.js

@ -112,15 +112,10 @@ const equivalents = {
}; };
function execute ( options, command ) { function execute ( options, command ) {
let external = command.external ? let external;
typeof options.external === 'function' ?
((fn, a) => { const commandExternal = ( command.external || '' ).split( ',' );
return function (id) { const optionsExternal = options.external;
return fn(id) || a.indexOf(id) !== -1;
};
})(options.external, command.external.split(',')) :
(options.external || []).concat(command.external.split(',')) :
options.external;
if ( command.globals ) { if ( command.globals ) {
let globals = Object.create( null ); let globals = Object.create( null );
@ -130,14 +125,22 @@ function execute ( options, command ) {
globals[ names[0] ] = names[1]; globals[ names[0] ] = names[1];
// Add missing Module IDs to external. // Add missing Module IDs to external.
if ( external.indexOf( names[0] ) === -1 ) { if ( commandExternal.indexOf( names[0] ) === -1 ) {
external.push( names[0] ); commandExternal.push( names[0] );
} }
}); });
command.globals = globals; command.globals = globals;
} }
if ( typeof optionsExternal === 'function' ) {
external = id => {
return optionsExternal( id ) || ~commandExternal.indexOf( id );
};
} else {
external = ( optionsExternal || [] ).concat( commandExternal );
}
options.onwarn = options.onwarn || stderr; options.onwarn = options.onwarn || stderr;
options.external = external; options.external = external;

Loading…
Cancel
Save