@@ -3,6 +3,8 @@ var path = require('path');
3
3
4
4
var browserify = require ( 'browserify' ) ;
5
5
var minify = require ( 'minify-stream' ) ;
6
+ var derequire = require ( 'derequire' ) ;
7
+ var through = require ( 'through2' ) ;
6
8
7
9
var constants = require ( './constants' ) ;
8
10
var compressAttributes = require ( './compress_attributes' ) ;
@@ -60,6 +62,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
60
62
61
63
if ( pathToMinBundle ) {
62
64
bundleStream
65
+ . pipe ( applyDerequire ( ) )
63
66
. pipe ( minify ( constants . uglifyOptions ) )
64
67
. pipe ( fs . createWriteStream ( pathToMinBundle ) )
65
68
. on ( 'finish' , function ( ) {
@@ -69,6 +72,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
69
72
}
70
73
71
74
bundleStream
75
+ . pipe ( applyDerequire ( ) )
72
76
. pipe ( fs . createWriteStream ( pathToBundle ) )
73
77
. on ( 'finish' , function ( ) {
74
78
logger ( pathToBundle ) ;
@@ -80,3 +84,14 @@ function logger(pathToOutput) {
80
84
var log = 'ok ' + path . basename ( pathToOutput ) ;
81
85
console . log ( log ) ;
82
86
}
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