Browse Source

Allow specifying multiple output targets.

Closes #655.
ghi-672
Brian Donovan 9 years ago
parent
commit
a3f2d17596
  1. 10
      bin/runRollup.js
  2. 1
      src/rollup.js
  3. 4
      test/cli/multiple-targets/_config.js
  4. 5
      test/cli/multiple-targets/_expected/cjs.js
  5. 3
      test/cli/multiple-targets/_expected/es6.js
  6. 1
      test/cli/multiple-targets/main.js
  7. 13
      test/cli/multiple-targets/rollup.config.js
  8. 26
      test/test.js

10
bin/runRollup.js

@ -143,6 +143,16 @@ function bundle ( options ) {
return bundle.write( options );
}
if ( options.targets ) {
var result = null;
options.targets.forEach( function ( target ) {
result = bundle.write(target);
});
return result;
}
if ( options.sourceMap && options.sourceMap !== 'inline' ) {
handleError({ code: 'MISSING_OUTPUT_OPTION' });
}

1
src/rollup.js

@ -27,6 +27,7 @@ const ALLOWED_KEYS = [
'plugins',
'preferConst',
'sourceMap',
'targets',
'treeshake',
'useStrict'
];

4
test/cli/multiple-targets/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'generates multiple output files when multiple targets are specified',
command: 'rollup -c'
};

5
test/cli/multiple-targets/_expected/cjs.js

@ -0,0 +1,5 @@
'use strict';
var main = 0;
module.exports = main;

3
test/cli/multiple-targets/_expected/es6.js

@ -0,0 +1,3 @@
var main = 0;
export default main;

1
test/cli/multiple-targets/main.js

@ -0,0 +1 @@
export default 0;

13
test/cli/multiple-targets/rollup.config.js

@ -0,0 +1,13 @@
export default {
entry: 'main.js',
targets: [
{
format: 'cjs',
dest: '_actual/cjs.js'
},
{
format: 'es6',
dest: '_actual/es6.js'
}
]
};

26
test/test.js

@ -76,7 +76,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () {
throw new Error( 'Missing expected error' );
}, function ( err ) {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, treeshake, useStrict' );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, targets, treeshake, useStrict' );
});
});
});
@ -353,9 +353,13 @@ describe( 'rollup', function () {
PATH: path.resolve( __dirname, '../bin' ) + path.delimiter + process.env.PATH
}
}, function ( err, code, stderr ) {
if ( err || config.error ) {
config.error( err );
return done();
if ( err ) {
if ( config.error ) {
config.error( err );
return done();
} else {
throw err;
}
}
if ( stderr ) console.error( stderr );
@ -409,6 +413,20 @@ describe( 'rollup', function () {
}
}
else if ( sander.existsSync( '_expected' ) && sander.statSync( '_expected' ).isDirectory() ) {
var error = null;
sander.readdirSync( '_expected' ).forEach( child => {
var expected = sander.readFileSync( path.join( '_expected', child ) ).toString();
var actual = sander.readFileSync( path.join( '_actual', child ) ).toString();
try {
assert.equal( normaliseOutput( actual ), normaliseOutput( expected ) );
} catch ( err ) {
error = err;
}
});
done( error );
}
else {
var expected = sander.readFileSync( '_expected.js' ).toString();
try {

Loading…
Cancel
Save