-
-
Notifications
You must be signed in to change notification settings - Fork 199
Use NamedModulesPlugin for HMR debugging #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c9b2495
to
dbe5793
Compare
lib/config-generator.js
Outdated
if (this.webpackConfig.isProduction()) { | ||
let moduleNamePlugin; | ||
if (this.webpackConfig.isProduction()) { | ||
// only enable if versioning is on, as it makes the assets *slightly* larger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a way to turn it ON otherwise too ? If you use query-string versioning with https://packagist.org/packages/incenteev/hashed-asset-bundle, having a stable file hash is important too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a .useStableModuleNames()
method, which is enabled automatically when using versioning ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof Unless you enable versioning, your output filenames will always be static and not changing (e.g. main.js
). This just controls the internal names used for the modules. Or am I missing a detail? Basically, I don't think the module naming scheme should be important externally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weaverryan my issue is stable module names, not stable output file names.
hashed-asset-bundle uses a (truncated) hash of the file content as version. So if you use numeric index for modules, the hash of the vendor module may change just because of reindexing module, busting the cache for nothing.
you use the HashedModuleIdsPlugin when versioning is enabled to ensure that the chunkHash stay consistent, but we have the same need when using hashed-asset-bundle.
I don't care about how modules are named. I care that vendor modules don't get renamed randomly between 2 deployments where only the app code changed and not vendors.
dbe5793
to
ec7a30c
Compare
@stof Ah, I totally understand now. I've updated the PR to always use one of the plugins, instead of adding a new option. Regardless of where you do versioning, it seems like an edge case to me to "be ok with" your asset contents often changing... even when you didn't make any code changes to it. So, at the cost of a slight increase in asset size (in one example I saw, the asset size went from 296kb to 300kb), I'd like to be consistent and always give this "expected" behavior. If someone later really wants to minimize their asset size at the expense of the content sometimes changing, they can make a request (and we can add a method to allow that to be configured). This feels like a more sensible default to me. |
@weaverryan fine with me |
lib/config-generator.js
Outdated
moduleNamePlugin = new webpack.NamedModulesPlugin(); | ||
} | ||
|
||
if (moduleNamePlugin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless check. It will always be set
lib/config-generator.js
Outdated
} | ||
|
||
if (moduleNamePlugin) { | ||
plugins.push(moduleNamePlugin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could put this directly above instead of using a moduleNamePlugin
variable.
lib/config-generator.js
Outdated
moduleNamePlugin = new webpack.HashedModuleIdsPlugin(); | ||
} else { | ||
// human-readable module names, helps debug in HMR | ||
// enable always when ! production for consistency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say when not production
instead of putting an operator in the middle of an English sentence
5185ff4
to
0a16b47
Compare
test/config-generator.js
Outdated
config.runtimeConfig.useDevServer = true; | ||
config.runtimeConfig.devServerUrl = 'http://localhost:8080/'; | ||
config.runtimeConfig.useHotModuleReplacement = false; | ||
config.outputPath = '/tmp/public'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this use a windows path on windows ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't matter here, because it's not what I'm testing for. I just need a path that won't cause the code to throw an exception internally (Unable to determine contentBase option...
) - and that logic for that exception is tested elsewhere with the proper paths. We could probably clean this file up a bit with some mocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pff, nevermind - I immediately saw the test failure after posting this. I'm trying a Windows path now to see if it'll keep things happy :)
00c7cdd
to
971a822
Compare
When using HMR, the name of your module shows up in the console. By default, since numbers are used, it looks like:
After:
... which at least makes a bit more sense :).
This adds a bit more logic:
In dev, always add
NamedModulesPlugin
. We actually only need this if you're using HMR... but I don't think there's a disadvantage of including it always, so I've done it to try to keep the dev environment as consistent as possible with itself.In prod, we only add
HashedModuleIdsPlugin
when versioning is enabled. We could at it always (for consistency), but it slightly increases the size of the built assets, because the module ids are longer.Enable
WebpackChunkHash
only when versioning is used, because it's the only time we use the[chunkhash]