diff --git a/lib/utils/DevServerPlugin.js b/lib/utils/DevServerPlugin.js index 4e7c554f64..33102f71dd 100644 --- a/lib/utils/DevServerPlugin.js +++ b/lib/utils/DevServerPlugin.js @@ -10,9 +10,11 @@ const EntryPlugin = webpack.EntryPlugin; class DevServerPlugin { /** * @param {?Object} options - Dev-Server options + * @param {?Object} logger - Dev-Server logger */ - constructor(options) { + constructor(options, logger) { this.options = options; + this.logger = logger; } /** @@ -163,6 +165,13 @@ class DevServerPlugin { additionalEntries.push(hotEntry); } + if (!isWebTarget) { + this.logger.info(`A non-web target was selected in dev server config.`); + if (this.options.liveReload) { + this.logger.warn(`Live reload will not work with a non-web target.`); + } + } + // use a hook to add entries if available if (EntryPlugin) { for (const additionalEntry of additionalEntries) { diff --git a/lib/utils/updateCompiler.js b/lib/utils/updateCompiler.js index db77355950..476405434b 100644 --- a/lib/utils/updateCompiler.js +++ b/lib/utils/updateCompiler.js @@ -4,10 +4,11 @@ const DevServerPlugin = require('./DevServerPlugin'); function updateCompiler(compiler, options) { const compilers = compiler.compilers || [compiler]; + const logger = compiler.getInfrastructureLogger('webpack-dev-server'); // eslint-disable-next-line no-shadow compilers.forEach((compiler) => { - new DevServerPlugin(options).apply(compiler); + new DevServerPlugin(options, logger).apply(compiler); }); } diff --git a/test/e2e/DevServer.test.js b/test/e2e/DevServer.test.js index e87f5884d5..88a587c6c1 100644 --- a/test/e2e/DevServer.test.js +++ b/test/e2e/DevServer.test.js @@ -95,6 +95,22 @@ describe('DevServer', () => { .catch(done); }); + it('should show a warning for live reloading with non-web target', (done) => { + testBin( + '--config ./test/fixtures/dev-server/default-config.js --target node --live-reload' + ) + .then((output) => { + expect(output.stderr).toContain( + 'A non-web target was selected in dev server config' + ); + expect(output.stderr).toContain( + 'Live reload will not work with a non-web target' + ); + done(); + }) + .catch(done); + }); + it('does not use client.path when default', (done) => { testBin('--config ./test/fixtures/dev-server/client-default-path-config.js') .then((output) => {