Skip to content

Commit c9b2495

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

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-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 = 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ describe('The config-generator function', () => {
485485
// is calculated as outputPath, but without the publicPath portion
486486
expect(actualConfig.devServer.contentBase).to.equal('/tmp/public');
487487
expect(actualConfig.devServer.publicPath).to.equal('/subdirectory/build/');
488+
expect(actualConfig.devServer.hot).to.be.false;
489+
});
490+
491+
it.only('hot mode', () => {
492+
const config = createConfig();
493+
config.runtimeConfig.useDevServer = true;
494+
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
495+
config.runtimeConfig.useHotModuleReplacement = true;
496+
config.publicPath = '/';
497+
config.outputPath = '/tmp';
498+
config.addEntry('main', './main');
499+
500+
const actualConfig = configGenerator(config);
501+
expect(actualConfig.devServer.hot).to.be.true;
502+
const moduleNamePlugin = findPlugin(webpack.NamedModulesPlugin, actualConfig.plugins);
503+
expect(moduleNamePlugin).to.not.be.undefined;
488504
});
489505
});
490506
});

0 commit comments

Comments
 (0)