Skip to content

Commit 44d4752

Browse files
committed
Apply derequire to generated bundles
Rewrite require calls in the generated bundles so that Browserify is able to consume the bundles when bundling new bundles. Solves issue #2902.
1 parent def6aa5 commit 44d4752

File tree

3 files changed

+158
-2
lines changed

3 files changed

+158
-2
lines changed

package-lock.json

+142-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"browserify-transform-tools": "^1.7.0",
123123
"check-node-version": "^3.2.0",
124124
"deep-equal": "^1.0.1",
125+
"derequire": "^2.0.6",
125126
"ecstatic": "^3.2.0",
126127
"eslint": "^4.19.1",
127128
"falafel": "^2.0.0",

tasks/util/browserify_wrapper.js

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var path = require('path');
33

44
var browserify = require('browserify');
55
var minify = require('minify-stream');
6+
var derequire = require('derequire');
7+
var through = require('through2');
68

79
var constants = require('./constants');
810
var 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

Comments
 (0)