From fca02171facbd2821a35d73ee65a0a70c74a693f Mon Sep 17 00:00:00 2001 From: Brian Donovan Date: Thu, 9 Jun 2016 07:00:45 -0700 Subject: [PATCH] Merge target options with main options. Fixes #701. --- bin/runRollup.js | 13 ++++++++++++- test/cli/multiple-targets-shared-config/_config.js | 4 ++++ .../_expected/cjs.js | 6 ++++++ .../_expected/cjs.js.map | 1 + .../_expected/es6.js | 4 ++++ .../_expected/es6.js.map | 1 + test/cli/multiple-targets-shared-config/main.js | 1 + .../rollup.config.js | 14 ++++++++++++++ 8 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/cli/multiple-targets-shared-config/_config.js create mode 100644 test/cli/multiple-targets-shared-config/_expected/cjs.js create mode 100644 test/cli/multiple-targets-shared-config/_expected/cjs.js.map create mode 100644 test/cli/multiple-targets-shared-config/_expected/es6.js create mode 100644 test/cli/multiple-targets-shared-config/_expected/es6.js.map create mode 100644 test/cli/multiple-targets-shared-config/main.js create mode 100644 test/cli/multiple-targets-shared-config/rollup.config.js diff --git a/bin/runRollup.js b/bin/runRollup.js index 38d5339..ed88549 100644 --- a/bin/runRollup.js +++ b/bin/runRollup.js @@ -171,6 +171,17 @@ function execute ( options, command ) { } } +function clone ( object ) { + return assign( {}, object ); +} + +function assign ( target, source ) { + Object.keys( source ).forEach( function ( key ) { + target[ key ] = source[ key ]; + }); + return target; +} + function bundle ( options ) { if ( !options.entry ) { handleError({ code: 'MISSING_INPUT_OPTION' }); @@ -185,7 +196,7 @@ function bundle ( options ) { var result = null; options.targets.forEach( function ( target ) { - result = bundle.write(target); + result = bundle.write( assign( clone( options ), target ) ); }); return result; diff --git a/test/cli/multiple-targets-shared-config/_config.js b/test/cli/multiple-targets-shared-config/_config.js new file mode 100644 index 0000000..6d7125c --- /dev/null +++ b/test/cli/multiple-targets-shared-config/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'uses shared config for each target', + command: 'rollup -c' +}; diff --git a/test/cli/multiple-targets-shared-config/_expected/cjs.js b/test/cli/multiple-targets-shared-config/_expected/cjs.js new file mode 100644 index 0000000..d3b3eb0 --- /dev/null +++ b/test/cli/multiple-targets-shared-config/_expected/cjs.js @@ -0,0 +1,6 @@ +'use strict'; + +var main = 0; + +module.exports = main; +//# sourceMappingURL=cjs.js.map \ No newline at end of file diff --git a/test/cli/multiple-targets-shared-config/_expected/cjs.js.map b/test/cli/multiple-targets-shared-config/_expected/cjs.js.map new file mode 100644 index 0000000..7010396 --- /dev/null +++ b/test/cli/multiple-targets-shared-config/_expected/cjs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cjs.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":";;WAAe,CAAC,CAAC,;;"} \ No newline at end of file diff --git a/test/cli/multiple-targets-shared-config/_expected/es6.js b/test/cli/multiple-targets-shared-config/_expected/es6.js new file mode 100644 index 0000000..e24bdc9 --- /dev/null +++ b/test/cli/multiple-targets-shared-config/_expected/es6.js @@ -0,0 +1,4 @@ +var main = 0; + +export default main; +//# sourceMappingURL=es6.js.map \ No newline at end of file diff --git a/test/cli/multiple-targets-shared-config/_expected/es6.js.map b/test/cli/multiple-targets-shared-config/_expected/es6.js.map new file mode 100644 index 0000000..ba7fc9c --- /dev/null +++ b/test/cli/multiple-targets-shared-config/_expected/es6.js.map @@ -0,0 +1 @@ +{"version":3,"file":"es6.js","sources":["../main.js"],"sourcesContent":["export default 0;\n"],"names":[],"mappings":"WAAe,CAAC,CAAC,;;"} \ No newline at end of file diff --git a/test/cli/multiple-targets-shared-config/main.js b/test/cli/multiple-targets-shared-config/main.js new file mode 100644 index 0000000..7f810d3 --- /dev/null +++ b/test/cli/multiple-targets-shared-config/main.js @@ -0,0 +1 @@ +export default 0; diff --git a/test/cli/multiple-targets-shared-config/rollup.config.js b/test/cli/multiple-targets-shared-config/rollup.config.js new file mode 100644 index 0000000..e99ab56 --- /dev/null +++ b/test/cli/multiple-targets-shared-config/rollup.config.js @@ -0,0 +1,14 @@ +export default { + entry: 'main.js', + sourceMap: true, + targets: [ + { + format: 'cjs', + dest: '_actual/cjs.js' + }, + { + format: 'es6', + dest: '_actual/es6.js' + } + ] +};