diff --git a/src/Bundle.js b/src/Bundle.js index c099301..950ae9c 100644 --- a/src/Bundle.js +++ b/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 ) diff --git a/test/function/plugins-can-manipulate-options/_config.js b/test/function/plugins-can-manipulate-options/_config.js new file mode 100644 index 0000000..a0e607c --- /dev/null +++ b/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 ); + } +} diff --git a/test/function/plugins-can-manipulate-options/answer.js b/test/function/plugins-can-manipulate-options/answer.js new file mode 100644 index 0000000..7a4e8a7 --- /dev/null +++ b/test/function/plugins-can-manipulate-options/answer.js @@ -0,0 +1 @@ +export default 42;