ctf0 / laravel-mix-versionhash

Auto append hash to file instead of using virtual one
MIT License
61 stars 18 forks source link

Manifest not updating after reverting change #36

Closed sevba closed 5 months ago

sevba commented 4 years ago

I'm not sure this is an issue with laravel-mix-versionhash, as it could also be related to webpack watch.

I noticed that the manifest file isn't updating if you revert a change, while running "npm run watch".

Steps to reproduce:

  1. Run "npm run watch" to build your project and watch for changes
  2. Check the manifest file: /assets/js/app.3d89dd.js
  3. Make any random change to your source code and save. This triggers webpack-watch to re-build.
  4. Check the manifest file: /assets/js/app.a9b031.js - perfect, manifest is updated
  5. Undo the random change, i.e. revert back to the state of the code from step 1.
  6. Check the manifest file: /assets/js/app.a9b031.js - issue, should be updated back to the old hash from step 2!

If you check the modified date of /assets/js/app.3d89dd.js you'll see that it was touched. Also in the asset list shown by the "npm run watch" command, I see the file with the hash 3d89dd.

If I shut down "npm run watch" and start it again (i.e. trigger a full re-build of my code) then the manifest is properly updated.

ctf0 commented 4 years ago

If I shut down "npm run watch" and start it again (i.e. trigger a full re-build of my code) then the manifest is properly updated.

u mean u get app.3d89dd.js back ?

sevba commented 4 years ago

If I shut down "npm run watch" and start it again (i.e. trigger a full re-build of my code) then the manifest is properly updated.

u mean u get app.3d89dd.js back ?

Exactly. So the problem only occurs when webpack watch is supposed to update the manifest. And only when you revert changes (i.e. when a file with the same hash was already built before).

I tried to delete the initial file (app.3d89dd.js) between step 4 and 5, to test if perhaps the issue occurs when webpack already finds an existing file (from an earlier build). This didn't fix it. So it appears that somehow webpack watch is still "aware" of earlier hashes.

Perhaps it caches earlier builds of modules and if it detects that there is actually nothing new (i.e. everything is already in its cache), it decides not to update the manifest?

sevba commented 4 years ago

Because this seemed like an issue with webpack caching, I tried to reproduce with mix.webpackConfig({ cache: false }); however that didn't solve it, the problem persists.

ctf0 commented 4 years ago

can u try with v1.0.8 of the plugin and reply back ?

sevba commented 4 years ago

can u try with v1.0.8 of the plugin and reply back ?

I just tried with v1.0.8 but the issue remains.

ctf0 commented 4 years ago

does the hash change as expected with mix.version () ?

sevba commented 4 years ago

Yes, it works as expected with the regular mix.version() feature.

The reason why I prefer your plug-in over the mix.version() feature is because it actually hashes the filename. This supports my blue/green deployment setup. I deploy my assets (including the compiled JS files) to AWS S3. When I deploy, both the old version (blue) and the new version (green) exist in S3, so a rollback is very easy.

ctf0 commented 4 years ago

@Erutan409 can u help with this?