laravel-mix: Manifest hash won't change!

  • Laravel Mix Version: 0.10.0
  • Node Version: v7.7.3
  • NPM Version: 4.1.2
  • OS: 10.12.4

Description:

manifes.js hash won’t change even app or vendor names had changed. If manifest is in browsers cache it will load the old app and vendor files.

Steps To Reproduce:

npm run production

<script src="/js/manifest.d41d8cd98f00b204e980.js"></script>
<script src="/js/vendor.0644ae2bcbd1e2178134.js"></script>
<script src="/js/app.d3d968be03d7943f18be.js"></script>
<script type="text/javascript" src="/js/home.40299b3f79c3bf7007fc.js"></script>

change something in app js files npm run production

<script src="/js/manifest.d41d8cd98f00b204e980.js"></script>
<script src="/js/vendor.0644ae2bcbd1e2178134.js"></script>
<script src="/js/app.4b2f4c54fb528e83e8f0.js"></script>
<script type="text/javascript" src="/js/home.40299b3f79c3bf7007fc.js"></script>

As you can see, app change from /js/app.d3d968be03d7943f18be.js to /js/app.4b2f4c54fb528e83e8f0.js but manifest is the same: /js/manifest.d41d8cd98f00b204e980.js

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

This is a “bug” in webpack-chunk-hash (forked from webpack-md5-hash which had the same bug), you can find a lot of official webpack example that show a manifest.d41d8cd98f00b204e980.jsfile.

see some related issue: https://github.com/alexindigo/webpack-chunk-hash/issues/7 https://github.com/erm0l0v/webpack-md5-hash/issues/9

I could trash fix it in my webpack.mix.js file by disabling the webpack-chunk-hash plugin, this rollback to the default webpack versioning which is able to generate a correct hash for the manifest file:

const { mix } = require('laravel-mix');

let WebpackChunkHash = function () {};
WebpackChunkHash.prototype.apply = () => {};
// Replace WebpackChunkHashPlugin with an empty function
mix.plugins.WebpackChunkHashPlugin = WebpackChunkHash;

This is how we solved this issue in our apps. After every mix recompile, we update mix-manifest.json with random integers at the end of the file.


.version()
.then((stats) => {

  // We're appending random int to the versioned files to guarantee
  // that all assets are fully re-cached on every new version (md5 sucks at this)

  let file = File.find(stats.compilation.options.output.path + '/mix-manifest.json');
  let assets = JSON.parse(file.read());

  let new_assets = {};
  Object.keys(assets).forEach(function (item) {
    let addedTimestamp = '-' + Date.now();
    new_assets[item] = assets[item] + addedTimestamp;
  });

  file.write(JSON.stringify(new_assets, null, 2));
})

Excited, I thought it’s a bug of webpack once… Here’s my monkey-patch:

const Module = require('module')
const origRequire = Module._load
Module._load = function(request, parent, isMain) {
  if (request === 'webpack-chunk-hash') {
    const ret = function () {}
    ret.prototype.apply = () => {}
    return ret
  }
  return origRequire(request, parent, isMain)
}

It looks like this is the md5 hash of an empty file:

simple test.js file:

let md5 = require('md5');
console.log(md5(''));

output: d41d8cd98f00b204e9800998ecf8427e