Skip to content

Commit

Permalink
Fix support for multi compiler in webpack 4
Browse files Browse the repository at this point in the history
Ref #1301
  • Loading branch information
SpaceK33z committed Feb 26, 2018
1 parent 9921ecc commit c375aa6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/Server.js
Expand Up @@ -65,12 +65,20 @@ function Server(compiler, options) {
});
compiler.apply(progressPlugin);
}
compiler.hooks.compile.tap('webpack-dev-server', invalidPlugin);
compiler.hooks.invalid.tap('webpack-dev-server', invalidPlugin);
compiler.hooks.done.tap('webpack-dev-server', (stats) => {
this._sendStats(this.sockets, stats.toJson(clientStats));
this._stats = stats;
});

const addCompilerHooks = (comp) => {
comp.hooks.compile.tap('webpack-dev-server', invalidPlugin);
comp.hooks.invalid.tap('webpack-dev-server', invalidPlugin);
comp.hooks.done.tap('webpack-dev-server', (stats) => {
this._sendStats(this.sockets, stats.toJson(clientStats));
this._stats = stats;
});
};
if (compiler.compilers) {
compiler.compilers.forEach(addCompilerHooks);
} else {
addCompilerHooks(compiler);
}

// Init express server
const app = this.app = new express(); // eslint-disable-line
Expand Down
23 changes: 23 additions & 0 deletions test/MultiCompiler.test.js
@@ -0,0 +1,23 @@
'use strict';

const request = require('supertest');
const helper = require('./helper');
const config = require('./fixtures/multi-compiler-config/webpack.config');

describe('MultiCompiler', () => {
let server;
let req;
before((done) => {
server = helper.start(config, {}, done);
req = request(server.app);
});

after(helper.close);

// TODO: this is a very basic test, optimally it should test multiple configs etc.
it('GET request to bundle', (done) => {
req.get('/main.js')
.expect('Content-Type', 'application/javascript; charset=UTF-8')
.expect(200, done);
});
});
3 changes: 3 additions & 0 deletions test/fixtures/multi-compiler-config/foo.js
@@ -0,0 +1,3 @@
'use strict';

console.log('Hey.');
11 changes: 11 additions & 0 deletions test/fixtures/multi-compiler-config/webpack.config.js
@@ -0,0 +1,11 @@
'use strict';

module.exports = [{
mode: 'development',
context: __dirname,
entry: './foo.js',
output: {
path: '/'
},
node: false
}];

0 comments on commit c375aa6

Please sign in to comment.