@@ -3,6 +3,8 @@ var path = require('path');
33
44var browserify = require ( 'browserify' ) ;
55var minify = require ( 'minify-stream' ) ;
6+ var derequire = require ( 'derequire' ) ;
7+ var through = require ( 'through2' ) ;
68
79var constants = require ( './constants' ) ;
810var compressAttributes = require ( './compress_attributes' ) ;
@@ -60,6 +62,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
6062
6163 if ( pathToMinBundle ) {
6264 bundleStream
65+ . pipe ( applyDerequire ( ) )
6366 . pipe ( minify ( constants . uglifyOptions ) )
6467 . pipe ( fs . createWriteStream ( pathToMinBundle ) )
6568 . on ( 'finish' , function ( ) {
@@ -69,6 +72,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
6972 }
7073
7174 bundleStream
75+ . pipe ( applyDerequire ( ) )
7276 . pipe ( fs . createWriteStream ( pathToBundle ) )
7377 . on ( 'finish' , function ( ) {
7478 logger ( pathToBundle ) ;
@@ -80,3 +84,14 @@ function logger(pathToOutput) {
8084 var log = 'ok ' + path . basename ( pathToOutput ) ;
8185 console . log ( log ) ;
8286}
87+
88+ function applyDerequire ( ) {
89+ var buf = '' ;
90+ return through ( function ( chunk , enc , next ) {
91+ buf += chunk . toString ( ) ;
92+ next ( ) ;
93+ } , function ( done ) {
94+ this . push ( derequire ( buf ) ) ;
95+ done ( ) ;
96+ } ) ;
97+ }
0 commit comments