Skip to content

Commit c375aa6

Browse files
committed
Fix support for multi compiler in webpack 4
Ref #1301
1 parent 9921ecc commit c375aa6

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

lib/Server.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,20 @@ function Server(compiler, options) {
6565
});
6666
compiler.apply(progressPlugin);
6767
}
68-
compiler.hooks.compile.tap('webpack-dev-server', invalidPlugin);
69-
compiler.hooks.invalid.tap('webpack-dev-server', invalidPlugin);
70-
compiler.hooks.done.tap('webpack-dev-server', (stats) => {
71-
this._sendStats(this.sockets, stats.toJson(clientStats));
72-
this._stats = stats;
73-
});
68+
69+
const addCompilerHooks = (comp) => {
70+
comp.hooks.compile.tap('webpack-dev-server', invalidPlugin);
71+
comp.hooks.invalid.tap('webpack-dev-server', invalidPlugin);
72+
comp.hooks.done.tap('webpack-dev-server', (stats) => {
73+
this._sendStats(this.sockets, stats.toJson(clientStats));
74+
this._stats = stats;
75+
});
76+
};
77+
if (compiler.compilers) {
78+
compiler.compilers.forEach(addCompilerHooks);
79+
} else {
80+
addCompilerHooks(compiler);
81+
}
7482

7583
// Init express server
7684
const app = this.app = new express(); // eslint-disable-line

test/MultiCompiler.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const request = require('supertest');
4+
const helper = require('./helper');
5+
const config = require('./fixtures/multi-compiler-config/webpack.config');
6+
7+
describe('MultiCompiler', () => {
8+
let server;
9+
let req;
10+
before((done) => {
11+
server = helper.start(config, {}, done);
12+
req = request(server.app);
13+
});
14+
15+
after(helper.close);
16+
17+
// TODO: this is a very basic test, optimally it should test multiple configs etc.
18+
it('GET request to bundle', (done) => {
19+
req.get('/main.js')
20+
.expect('Content-Type', 'application/javascript; charset=UTF-8')
21+
.expect(200, done);
22+
});
23+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log('Hey.');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = [{
4+
mode: 'development',
5+
context: __dirname,
6+
entry: './foo.js',
7+
output: {
8+
path: '/'
9+
},
10+
node: false
11+
}];

0 commit comments

Comments
 (0)