Skip to content

Commit 43fca8f

Browse files
committed
fix: show warning for non-web targets
1 parent 728effc commit 43fca8f

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

lib/Server.js

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const getColorsOption = require('./utils/getColorsOption');
3333
const setupExitSignals = require('./utils/setupExitSignals');
3434
const findPort = require('./utils/findPort');
3535
const schema = require('./options.json');
36+
const isWebTarget = require('./utils/isWebTarget');
3637

3738
if (!process.env.WEBPACK_SERVE) {
3839
process.env.WEBPACK_SERVE = true;
@@ -662,6 +663,13 @@ class Server {
662663
);
663664
}
664665

666+
if (!isWebTarget(this.compiler.options)) {
667+
this.logger.info(`A non-web target was selected in dev server config.`);
668+
if (this.options.liveReload) {
669+
this.logger.info(`Live reload will not work with a non-web target.`);
670+
}
671+
}
672+
665673
if (this.options.open || this.options.openPage) {
666674
runOpen(localUrlForTerminal, this.options, this.logger);
667675
}

lib/utils/DevServerPlugin.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const webpack = require('webpack');
44
const createDomain = require('./createDomain');
55
const getSocketClientPath = require('./getSocketClientPath');
6+
const isWebTarget = require('./isWebTarget');
67

78
// @ts-ignore
89
const EntryPlugin = webpack.EntryPlugin;
@@ -137,24 +138,11 @@ class DevServerPlugin {
137138

138139
compilerOptions.plugins = compilerOptions.plugins || [];
139140

140-
/** @type {boolean} */
141-
const isWebTarget = compilerOptions.externalsPresets
142-
? compilerOptions.externalsPresets.web
143-
: [
144-
'web',
145-
'webworker',
146-
'electron-renderer',
147-
'node-webkit',
148-
// eslint-disable-next-line no-undefined
149-
undefined,
150-
null,
151-
].includes(compilerOptions.target);
152-
153141
/** @type {Entry} */
154142
const additionalEntries = checkInject(
155143
options.injectClient,
156144
compilerOptions,
157-
isWebTarget
145+
isWebTarget(compilerOptions)
158146
)
159147
? [clientEntry]
160148
: [];

lib/utils/isWebTarget.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const isWebTarget = (compilerOptions) =>
4+
compilerOptions.externalsPresets
5+
? compilerOptions.externalsPresets.web
6+
: [
7+
'web',
8+
'webworker',
9+
'electron-renderer',
10+
'node-webkit',
11+
// eslint-disable-next-line no-undefined
12+
undefined,
13+
null,
14+
].includes(compilerOptions.target);
15+
16+
module.exports = isWebTarget;

test/cli/cli.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ describe('CLI', () => {
165165
});
166166
});
167167

168+
it('should show a warning for live reloading with non-web target', (done) => {
169+
testBin('--target node --live-reload')
170+
.then((output) => {
171+
expect(output.stderr).toContain(
172+
'A non-web target was selected in dev server config'
173+
);
174+
expect(output.stderr).toContain(
175+
'Live reload will not work with a non-web target'
176+
);
177+
done();
178+
})
179+
.catch(done);
180+
});
181+
168182
it('should log static', (done) => {
169183
testBin(
170184
'--no-color',

0 commit comments

Comments
 (0)