Closed grahamlyus closed 7 years ago
Thanks for going to the effort to make this issue - details are :100:.
I can't get around to jumping into an issue like this atm, but I'll dump some notes so I can get into it later (or ideally @insin will jump in).
Notes:
Related issues for reference: webpack-md5-hash create-react-app webpack related nwb issue
Thanks for the thorough investigation and the repro repo 👍
Will drop use of md5-hash in this case, as it looks like Webpack 2 now does what you'd expect with chunk hashes.
It also used to be the case that if you just changed some extracted CSS, the chunkhash of JS emitted from the same chunk would also change. I'm not seeing that any more and I can confirm Workaround 1 works for me as for you.
This issue is a:
I recently encountered a problem where I changed some imports in a split chunk, which caused the app chunk output to change without it's hash changing. Because the app chunk is cached, mayhem ensues due to webpack exports no longer being consistent between chunks.
I've found two workarounds:
webpack-md5hash
fromcreateWebpackConfig.js
- this causes both the app and split chunks hash to change.transform-es2015-modules-commonjs
to the babel plugins config to counteract themodules: false
config. This disables the tree-shaking and causes only the split chunk hash to change.I've set up a small test project that can reproduce the issue: https://github.com/grahamlyus/nwb-chunkhash-issue
Default nwb settings
split.js:
yarn build
:Changing the import in split.js:
yarn build
:diff of
app.f709a8e5.js
c changes from 2 to 3 which won't be picked up as the script will be cached as the filename has not changed:diff of split chunk only the chunk hash has changed:
Workaround 1 - webpack-md5hash removed from (createWebpackConfig) config
import { CONSTANT_2 } from './constants.js'
:import { CONSTANT_3 } from './constants.js'
:diff of app chunks (hash has changed):
The split chunk is identical, and that is ok, as the reference
c
now points to the other import.Workaround 2 - babel plugin transform-es2015-modules-commonjs in nwb.config.js
import { CONSTANT_2 } from './constants.js'
:import { CONSTANT_3 } from './constants.js'
:app chunk is identical
split chunk diff correctly uses
CONSTANT_3
:There are a couple of issues on the https://github.com/erm0l0v/webpack-md5-hash/issues repo alluding to similar problems.
I'm using Workaround 2 as there's no external way to use Workaround 1. It disables tree-shaking, but I haven't seen much of a difference in chunk sizes to be honest - I'm not sure they've figured it out completely yet, for instance: https://github.com/webpack/webpack/issues/2867. This also makes more sense that only the split chunk changes as that is where the original source was changed.
It would be nice to remove webpack-md5-hash even if via nwb.config.js somehow.
Thoughts?