Skip to content

Commit dbe5793

Browse files
committed
Always enabling the "named" plugins in dev to help with HMR debugging
1 parent eaff944 commit dbe5793

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

lib/config-generator.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,26 @@ class ConfigGenerator {
320320
* * https://github.com/webpack/webpack.js.org/issues/652#issuecomment-273324529
321321
* * https://webpack.js.org/guides/caching/#deterministic-hashes
322322
*/
323-
// when not using versioning, none of this is important
324-
if (this.webpackConfig.useVersioning) {
325-
let moduleNamePlugin;
326-
if (this.webpackConfig.isProduction()) {
323+
let moduleNamePlugin;
324+
if (this.webpackConfig.isProduction()) {
325+
// only enable if versioning is on, as it makes the assets *slightly* larger
326+
if (this.webpackConfig.useVersioning) {
327327
// shorter, and obfuscated module ids
328328
moduleNamePlugin = new webpack.HashedModuleIdsPlugin();
329-
} else {
330-
// human-readable module names, helps debug in HMR
331-
moduleNamePlugin = new webpack.NamedModulesPlugin();
332329
}
333-
plugins = plugins.concat([
334-
moduleNamePlugin,
335-
new WebpackChunkHash()
336-
]);
330+
} else {
331+
// human-readable module names, helps debug in HMR
332+
// enable always when ! production for consistency
333+
moduleNamePlugin = new webpack.NamedModulesPlugin();
334+
}
335+
336+
if (moduleNamePlugin) {
337+
plugins.push(moduleNamePlugin);
338+
}
339+
340+
if (this.webpackConfig.useVersioning) {
341+
// enables the [chunkhash] ability
342+
plugins.push(new WebpackChunkHash());
337343
}
338344

339345
if (Object.keys(this.webpackConfig.providedVariables).length > 0) {

test/config-generator.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ describe('The config-generator function', () => {
458458
const config = createConfig();
459459
config.runtimeConfig.useDevServer = true;
460460
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
461+
config.runtimeConfig.useHotModuleReplacement = false;
461462
config.outputPath = '/tmp/public/build';
462463
config.setPublicPath('/build/');
463464
config.addEntry('main', './main');
@@ -467,6 +468,7 @@ describe('The config-generator function', () => {
467468
// is calculated as outputPath, but without the publicPath portion
468469
expect(actualConfig.devServer.contentBase).to.equal('/tmp/public');
469470
expect(actualConfig.devServer.publicPath).to.equal('/build/');
471+
expect(actualConfig.devServer.hot).to.be.false;
470472

471473
});
472474

@@ -486,5 +488,18 @@ describe('The config-generator function', () => {
486488
expect(actualConfig.devServer.contentBase).to.equal('/tmp/public');
487489
expect(actualConfig.devServer.publicPath).to.equal('/subdirectory/build/');
488490
});
491+
492+
it('hot mode', () => {
493+
const config = createConfig();
494+
config.runtimeConfig.useDevServer = true;
495+
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
496+
config.runtimeConfig.useHotModuleReplacement = true;
497+
config.publicPath = '/';
498+
config.outputPath = '/tmp';
499+
config.addEntry('main', './main');
500+
501+
const actualConfig = configGenerator(config);
502+
expect(actualConfig.devServer.hot).to.be.true;
503+
});
489504
});
490505
});

0 commit comments

Comments
 (0)