Skip to content

Commit 7919f8f

Browse files
committed
bug #899 Fixing support for webpack-dev-server v4 (weaverryan)
This PR was squashed before being merged into the main branch. Discussion ---------- Fixing support for webpack-dev-server v4 Fixes #893 Commits ------- 23a981f Fixing support for webpack-dev-server v4
2 parents 4095893 + 23a981f commit 7919f8f

8 files changed

+6
-104
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* `terser-webpack-plugin` from 1 to 5
1313
* `webpack-cli` from 3 to 4
1414
* `webpack-manifest-plugin` from 2 to 3
15-
* `webpack-manifest-plugin` from 3 to 4-beta
15+
* `webpack-dev-server` from 3 to 4-beta [CHANGELOG](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-beta0-2020-11-27)
1616

1717
* [DEPENDENCY SUPPORT CHANGES] Encore has changed what versions it supports
1818
of the following packages:

bin/encore.js

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function showUsageInstructions() {
7777
console.log(` ${chalk.green('dev-server')} : runs webpack-dev-server`);
7878
console.log(` - ${chalk.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
7979
console.log(` - ${chalk.yellow('--port')} The port the webpack-dev-server will bind to`);
80-
console.log(` - ${chalk.yellow('--hot')} Enable HMR on webpack-dev-server`);
8180
console.log(` - ${chalk.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
8281
console.log(' - Supports any webpack-dev-server options');
8382
console.log();

lib/WebpackConfig.js

-4
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,6 @@ class WebpackConfig {
995995
return this.runtimeConfig.devServerHttps;
996996
}
997997

998-
useHotModuleReplacementPlugin() {
999-
return this.runtimeConfig.useHotModuleReplacement;
1000-
}
1001-
1002998
isProduction() {
1003999
return this.runtimeConfig.environment === 'production';
10041000
}

lib/config-generator.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -570,17 +570,15 @@ class ConfigGenerator {
570570
const contentBase = pathUtil.getContentBase(this.webpackConfig);
571571

572572
const devServerOptions = {
573-
contentBase: contentBase,
574-
// this doesn't appear to be necessary, but here in case
575-
publicPath: this.webpackConfig.getRealPublicPath(),
573+
static: {
574+
directory: contentBase,
575+
// this doesn't appear to be necessary, but here in case
576+
publicPath: this.webpackConfig.getRealPublicPath(),
577+
},
576578
// avoid CORS concerns trying to load things like fonts from the dev server
577579
headers: { 'Access-Control-Allow-Origin': '*' },
578-
hot: this.webpackConfig.useHotModuleReplacementPlugin(),
579-
// required by FriendlyErrorsWebpackPlugin
580-
quiet: true,
581580
compress: true,
582581
historyApiFallback: true,
583-
watchOptions: this.buildWatchOptionsConfig(),
584582
https: this.webpackConfig.useDevServerInHttps()
585583
};
586584

lib/config/RuntimeConfig.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class RuntimeConfig {
2020
this.devServerUrl = null;
2121
this.devServerHttps = null;
2222
this.devServerKeepPublicPath = false;
23-
this.useHotModuleReplacement = false;
2423
this.outputJson = false;
2524
this.profile = false;
2625

lib/config/parse-runtime.js

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = function(argv, cwd) {
4242

4343
runtimeConfig.useDevServer = true;
4444
runtimeConfig.devServerHttps = argv.https;
45-
runtimeConfig.useHotModuleReplacement = argv.hot || false;
4645
runtimeConfig.devServerKeepPublicPath = argv.keepPublicPath || false;
4746

4847
if (typeof argv.public === 'string') {

test/config-generator.js

-80
Original file line numberDiff line numberDiff line change
@@ -613,33 +613,6 @@ describe('The config-generator function', () => {
613613
expect(actualConfig.devServer).to.be.undefined;
614614
});
615615

616-
it('devServer no hot mode', () => {
617-
const config = createConfig();
618-
config.runtimeConfig.useDevServer = true;
619-
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
620-
config.runtimeConfig.useHotModuleReplacement = false;
621-
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
622-
config.setPublicPath('/');
623-
config.addEntry('main', './main');
624-
625-
const actualConfig = configGenerator(config);
626-
expect(actualConfig.devServer).to.not.be.undefined;
627-
expect(actualConfig.devServer.hot).to.be.false;
628-
});
629-
630-
it('hot mode', () => {
631-
const config = createConfig();
632-
config.runtimeConfig.useDevServer = true;
633-
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
634-
config.runtimeConfig.useHotModuleReplacement = true;
635-
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
636-
config.setPublicPath('/');
637-
config.addEntry('main', './main');
638-
639-
const actualConfig = configGenerator(config);
640-
expect(actualConfig.devServer.hot).to.be.true;
641-
});
642-
643616
it('devServer with custom options', () => {
644617
const config = createConfig();
645618
config.runtimeConfig.useDevServer = true;
@@ -664,59 +637,6 @@ describe('The config-generator function', () => {
664637
},
665638
});
666639
});
667-
668-
it('devServer with custom watch options', () => {
669-
const config = createConfig();
670-
config.runtimeConfig.useDevServer = true;
671-
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
672-
config.runtimeConfig.useHotModuleReplacement = true;
673-
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
674-
config.setPublicPath('/');
675-
config.addEntry('main', './main');
676-
677-
config.configureWatchOptions(watchOptions => {
678-
watchOptions.poll = 250;
679-
});
680-
681-
const actualConfig = configGenerator(config);
682-
683-
expect(actualConfig.watchOptions).to.deep.equals({
684-
'ignored': /node_modules/,
685-
'poll': 250,
686-
});
687-
expect(actualConfig.devServer.watchOptions).to.deep.equals({
688-
'ignored': /node_modules/,
689-
'poll': 250,
690-
});
691-
});
692-
693-
it('devServer with custom options and watch options', () => {
694-
const config = createConfig();
695-
config.runtimeConfig.useDevServer = true;
696-
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
697-
config.runtimeConfig.useHotModuleReplacement = true;
698-
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
699-
config.setPublicPath('/');
700-
config.addEntry('main', './main');
701-
702-
config.configureWatchOptions(watchOptions => {
703-
watchOptions.poll = 250;
704-
});
705-
config.configureDevServerOptions(options => {
706-
// should take precedence over `configureWatchOptions()`
707-
options.watchOptions.poll = 500;
708-
});
709-
710-
const actualConfig = configGenerator(config);
711-
expect(actualConfig.watchOptions).to.deep.equals({
712-
'ignored': /node_modules/,
713-
'poll': 250,
714-
});
715-
expect(actualConfig.devServer.watchOptions).to.deep.equals({
716-
'ignored': /node_modules/,
717-
'poll': 500,
718-
});
719-
});
720640
});
721641

722642
describe('test for addPlugin config', () => {

test/config/parse-runtime.js

-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ describe('parse-runtime', () => {
6868
expect(config.environment).to.equal('dev');
6969
expect(config.useDevServer).to.be.true;
7070
expect(config.devServerUrl).to.equal('http://localhost:8080/');
71-
expect(config.useHotModuleReplacement).to.be.false;
7271
expect(config.devServerKeepPublicPath).to.be.false;
7372
});
7473

@@ -132,14 +131,6 @@ describe('parse-runtime', () => {
132131
expect(config.babelRcFileExists).to.be.true;
133132
});
134133

135-
it('dev-server command hot', () => {
136-
const testDir = createTestDirectory();
137-
const config = parseArgv(createArgv(['dev-server', '--hot']), testDir);
138-
139-
expect(config.useDevServer).to.be.true;
140-
expect(config.useHotModuleReplacement).to.be.true;
141-
});
142-
143134
it('dev-server command --keep-public-path', () => {
144135
const testDir = createTestDirectory();
145136
const config = parseArgv(createArgv(['dev-server', '--keep-public-path']), testDir);

0 commit comments

Comments
 (0)