Skip to content

Commit

Permalink
Make bundler middleware usage intuitive (#449)
Browse files Browse the repository at this point in the history
* Make bundler middleware usage intuitive

* Fix middleware test

Specifically bundling `/commonjs/index.js` in the middleware test before running
the `should produce two bundles when importing a CSS file` one
seems to cause `bunde()` in the latter to throw.
  • Loading branch information
kootoopas authored and devongovett committed Jan 1, 2018
1 parent dc4acd8 commit b9004fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class Bundler extends EventEmitter {
}

middleware() {
this.bundle();
return Server.middleware(this);
}

Expand Down
14 changes: 14 additions & 0 deletions test/bundler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const assert = require('assert');
const {bundler} = require('./utils');

describe('bundler', function() {
it('should bundle once before exporting middleware', function(done) {
let b = bundler(__dirname + '/integration/bundler-middleware/index.js');
b.middleware();

setTimeout(() => {
assert(b.mainAsset);
done();
}, 300);
});
});
5 changes: 5 additions & 0 deletions test/integration/bundler-middleware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var local = require('./local');

module.exports = function () {
return local.a + local.b;
};
2 changes: 2 additions & 0 deletions test/integration/bundler-middleware/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.a = 1;
exports.b = 2;

0 comments on commit b9004fc

Please sign in to comment.