Skip to content

Commit

Permalink
fix: show warning for non-web targets
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Mar 19, 2021
1 parent 1dde662 commit 790f08f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/utils/DevServerPlugin.js
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/updateCompiler.js
Expand Up @@ -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);
});
}

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/DevServer.test.js
Expand Up @@ -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) => {
Expand Down

0 comments on commit 790f08f

Please sign in to comment.