From c924d5433c10a90aa50bf75e1615478fc11992d0 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Wed, 21 Oct 2015 12:32:14 -0400 Subject: [PATCH] support plugins that return transform and intro functions --- src/Bundle.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 60bba22..6066eba 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -19,6 +19,8 @@ export default class Bundle { this.entry = options.entry; this.entryModule = null; + this.plugins = ensureArray( options.plugins ); + this.resolveId = first( ensureArray( options.resolveId ).concat( defaultResolver ) ); this.load = first( ensureArray( options.load ).concat( defaultLoader ) ); @@ -28,7 +30,9 @@ export default class Bundle { }; this.loadOptions = {}; - this.transformers = ensureArray( options.transform ); + this.transformers = ensureArray( options.transform ).concat( + this.plugins.map( plugin => plugin.transform ).filter( Boolean ) + ); this.pending = blank(); this.moduleById = blank(); @@ -171,7 +175,14 @@ export default class Bundle { } }); - if ( options.intro ) magicString.prepend( options.intro + '\n' ); + const intro = [ options.intro ] + .concat( + this.plugins.map( plugin => plugin.intro && plugin.intro() ) + ) + .filter( Boolean ) + .join( '\n\n' ); + + if ( intro ) magicString.prepend( intro + '\n' ); if ( options.outro ) magicString.append( '\n' + options.outro ); const indentString = getIndentString( magicString, options );