Skip to content
  • Sponsor webpack/webpack-dev-server

  • Notifications You must be signed in to change notification settings
  • Fork 1.5k

fix: show warning for non-web targets #3094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ class Server {

// eslint-disable-next-line no-shadow
compilers.forEach((compiler) => {
new DevServerPlugin(this.options).apply(compiler);
new DevServerPlugin(this.options, this.logger).apply(compiler);
});
}

11 changes: 10 additions & 1 deletion lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
@@ -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;
}

/**
@@ -190,6 +192,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) {
18 changes: 17 additions & 1 deletion test/e2e/DevServer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { testBin } = require('../helpers/test-bin');
const { testBin, normalizeStderr } = require('../helpers/test-bin');
const isWebpack5 = require('../helpers/isWebpack5');

describe('DevServer', () => {
@@ -124,4 +124,20 @@ describe('DevServer', () => {
.catch(done);
}
);

it('should show a warning for live reloading with non-web target', (done) => {
testBin(
'--target node --live-reload',
'./test/fixtures/dev-server/default-config.js'
)
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(
normalizeStderr(output.stderr, { ipv6: true })
).toMatchSnapshot();

done();
})
.catch(done);
});
});
11 changes: 11 additions & 0 deletions test/e2e/__snapshots__/DevServer.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DevServer should show a warning for live reloading with non-web target 1`] = `
"<i> [webpack-dev-server] A non-web target was selected in dev server config.
<w> [webpack-dev-server] Live reload will not work with a non-web target.
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
`;
11 changes: 11 additions & 0 deletions test/e2e/__snapshots__/DevServer.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DevServer should show a warning for live reloading with non-web target 1`] = `
"<i> [webpack-dev-server] A non-web target was selected in dev server config.
<w> [webpack-dev-server] Live reload will not work with a non-web target.
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
`;