Skip to content

Commit c320c3e

Browse files
committed
Always enabling the "named" plugins in dev to help with HMR debugging
1 parent 5c2157e commit c320c3e

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
@@ -324,20 +324,26 @@ class ConfigGenerator {
324324
* * https://github.com/webpack/webpack.js.org/issues/652#issuecomment-273324529
325325
* * https://webpack.js.org/guides/caching/#deterministic-hashes
326326
*/
327-
// when not using versioning, none of this is important
328-
if (this.webpackConfig.useVersioning) {
329-
let moduleNamePlugin;
330-
if (this.webpackConfig.isProduction()) {
327+
let moduleNamePlugin;
328+
if (this.webpackConfig.isProduction()) {
329+
// only enable if versioning is on, as it makes the assets *slightly* larger
330+
if (this.webpackConfig.useVersioning) {
331331
// shorter, and obfuscated module ids
332332
moduleNamePlugin = new webpack.HashedModuleIdsPlugin();
333-
} else {
334-
// human-readable module names, helps debug in HMR
335-
moduleNamePlugin = new webpack.NamedModulesPlugin();
336333
}
337-
plugins = plugins.concat([
338-
moduleNamePlugin,
339-
new WebpackChunkHash()
340-
]);
334+
} else {
335+
// human-readable module names, helps debug in HMR
336+
// enable always when ! production for consistency
337+
moduleNamePlugin = new webpack.NamedModulesPlugin();
338+
}
339+
340+
if (moduleNamePlugin) {
341+
plugins.push(moduleNamePlugin);
342+
}
343+
344+
if (this.webpackConfig.useVersioning) {
345+
// enables the [chunkhash] ability
346+
plugins.push(new WebpackChunkHash());
341347
}
342348

343349
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
@@ -471,6 +471,7 @@ describe('The config-generator function', () => {
471471
const config = createConfig();
472472
config.runtimeConfig.useDevServer = true;
473473
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
474+
config.runtimeConfig.useHotModuleReplacement = false;
474475
config.outputPath = '/tmp/public/build';
475476
config.setPublicPath('/build/');
476477
config.addEntry('main', './main');
@@ -480,6 +481,7 @@ describe('The config-generator function', () => {
480481
// is calculated as outputPath, but without the publicPath portion
481482
expect(actualConfig.devServer.contentBase).to.equal('/tmp/public');
482483
expect(actualConfig.devServer.publicPath).to.equal('/build/');
484+
expect(actualConfig.devServer.hot).to.be.false;
483485

484486
});
485487

@@ -499,6 +501,19 @@ describe('The config-generator function', () => {
499501
expect(actualConfig.devServer.contentBase).to.equal('/tmp/public');
500502
expect(actualConfig.devServer.publicPath).to.equal('/subdirectory/build/');
501503
});
504+
505+
it('hot mode', () => {
506+
const config = createConfig();
507+
config.runtimeConfig.useDevServer = true;
508+
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
509+
config.runtimeConfig.useHotModuleReplacement = true;
510+
config.publicPath = '/';
511+
config.outputPath = '/tmp';
512+
config.addEntry('main', './main');
513+
514+
const actualConfig = configGenerator(config);
515+
expect(actualConfig.devServer.hot).to.be.true;
516+
});
502517
});
503518

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

0 commit comments

Comments
 (0)