1

I'm code splitting vendor and app into chunks via CommonsChunkPlugin. When I build twice I expect the vendor chunk to be unchanged, but it changes :(

Steps to replicate:

  1. Clone https://github.com/mattcolman/webpack-vendor-chunk-test
  2. Run yarn, then yarn analyzeBundle, then yarn analyzeBundle again.
  3. Notice the vendor chunk hash has changed.

The diff between the 2 bundles shows that the TIME_STAMP I provide via the DefinePlugin is ending up in the vendor chunk, however this code is always inside a code block checking for "development" === 'test', so I would have thought this code gets removed on production.

I actually expected the code for injecting TIME_STAMP would end up in the app bundle, that would be fine, but it's not the case.

Any help would be appreciated! Thanks in advance!

  • ok I found a solution to the problem. Basically React was also referencing `process.env` in their code. Which meant my variables that I also attached to `process.env` were changing my vendor hash. Solution was to move my own variables such a BUILD_VERSION and TIME_STAMP off of `process.env`. More good info at https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31 and https://github.com/webpack/webpack/issues/1315 – Matt Colman Jun 21 '17 at 03:59

0 Answers0