Browse Source

Merge pull request #371 from rollup/manipulate-options

allow plugins to manipulate options
gh-384
Rich Harris 9 years ago
parent
commit
775366c010
  1. 10
      src/Bundle.js
  2. 18
      test/function/plugins-can-manipulate-options/_config.js
  3. 1
      test/function/plugins-can-manipulate-options/answer.js

10
src/Bundle.js

@ -17,11 +17,17 @@ import { isRelative } from './utils/path.js';
export default class Bundle {
constructor ( options ) {
this.plugins = ensureArray( options.plugins );
this.plugins.forEach( plugin => {
if ( plugin.options ) {
options = plugin.options( options ) || options;
}
});
this.entry = options.entry;
this.entryModule = null;
this.plugins = ensureArray( options.plugins );
this.resolveId = first(
this.plugins
.map( plugin => plugin.resolveId )

18
test/function/plugins-can-manipulate-options/_config.js

@ -0,0 +1,18 @@
var path = require( 'path' );
var assert = require( 'assert' );
module.exports = {
description: 'plugins can manipulate the options object',
options: {
plugins: [
{
options: function ( options ) {
options.entry = path.resolve( __dirname, 'answer.js' );
}
}
]
},
exports: function ( answer ) {
assert.equal( answer, 42 );
}
}

1
test/function/plugins-can-manipulate-options/answer.js

@ -0,0 +1 @@
export default 42;
Loading…
Cancel
Save