Skip to content

Commit 71a9eb9

Browse files
committed
fix: show warning for non-web targets
1 parent 257e2eb commit 71a9eb9

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Server {
8484

8585
// eslint-disable-next-line no-shadow
8686
compilers.forEach((compiler) => {
87-
new DevServerPlugin(this.options).apply(compiler);
87+
new DevServerPlugin(this.options, this.logger).apply(compiler);
8888
});
8989
}
9090

lib/utils/DevServerPlugin.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ const EntryPlugin = webpack.EntryPlugin;
1010
class DevServerPlugin {
1111
/**
1212
* @param {?Object} options - Dev-Server options
13+
* @param {?Object} logger - Dev-Server logger
1314
*/
14-
constructor(options) {
15+
constructor(options, logger) {
1516
this.options = options;
17+
this.logger = logger;
1618
}
1719

1820
/**
@@ -190,6 +192,13 @@ class DevServerPlugin {
190192
additionalEntries.push(hotEntry);
191193
}
192194

195+
if (!isWebTarget) {
196+
this.logger.info(`A non-web target was selected in dev server config.`);
197+
if (this.options.liveReload) {
198+
this.logger.warn(`Live reload will not work with a non-web target.`);
199+
}
200+
}
201+
193202
// use a hook to add entries if available
194203
if (EntryPlugin) {
195204
for (const additionalEntry of additionalEntries) {

test/e2e/DevServer.test.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

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

66
describe('DevServer', () => {
@@ -124,4 +124,20 @@ describe('DevServer', () => {
124124
.catch(done);
125125
}
126126
);
127+
128+
it('should show a warning for live reloading with non-web target', (done) => {
129+
testBin(
130+
'--target node --live-reload',
131+
'./test/fixtures/dev-server/default-config.js'
132+
)
133+
.then((output) => {
134+
expect(output.exitCode).toEqual(0);
135+
expect(
136+
normalizeStderr(output.stderr, { ipv6: true })
137+
).toMatchSnapshot();
138+
139+
done();
140+
})
141+
.catch(done);
142+
});
127143
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DevServer should show a warning for live reloading with non-web target 1`] = `
4+
"<i> [webpack-dev-server] A non-web target was selected in dev server config.
5+
<w> [webpack-dev-server] Live reload will not work with a non-web target.
6+
<i> [webpack-dev-server] Project is running at:
7+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
8+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
9+
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
10+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
11+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`DevServer should show a warning for live reloading with non-web target 1`] = `
4+
"<i> [webpack-dev-server] A non-web target was selected in dev server config.
5+
<w> [webpack-dev-server] Live reload will not work with a non-web target.
6+
<i> [webpack-dev-server] Project is running at:
7+
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
8+
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
9+
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
10+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
11+
`;

0 commit comments

Comments
 (0)