Skip to content

Instantly share code, notes, and snippets.

@Volune
Last active December 15, 2015 09:18
Show Gist options
  • Save Volune/5236967 to your computer and use it in GitHub Desktop.
Save Volune/5236967 to your computer and use it in GitHub Desktop.
Try to reproduce browserify/browserify#338, sometime fails because the bug is dependent of results order of asynchronous calls
var common = require('./common');
common.log('A');
module.exports.log = require('./logger').log;
module.exports.log = function() {
if (typeof console != 'undefined') {
console.log.apply(console, arguments);
}
if (typeof document != 'undefined') {
var index;
for (index = 0; index < arguments.length; ++index) {
document.write(arguments[index] + '');
}
}
};
{
"name": "test_br2_bug",
"version": "0.1.0",
"dependencies": {
"express": "3.0.x",
"browserify": "2.7.1"
}
}
var path = require('path');
var browserify = require('browserify');
var express = require('express');
var brA = browserify(path.resolve(__dirname, 'a.js'));
brA.require(path.resolve(__dirname, 'common.js'), {expose: true});
var app = express();
app.all('/a.js', function (req, res) {
brA.bundle({}, function sendBundleResult(err, src) {
if (err)
res.send(500, err);
else {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/javascript');
res.end(src);
}
});
});
app.use(express.static(__dirname));
var port = 8088;
app.listen(port, function () {
console.info("Serving http://localhost:%d/test.html", port);
});
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript" src="a.js"></script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment