Laravel-mix: In production mix.version() not updating app.js hash

Created on 10 Apr 2018  路  7Comments  路  Source: JeffreyWay/laravel-mix

Environment:

  • Laravel Mix version: 2.1.11
  • Node Version: 8.7.0
  • NPM version: 5.6.0
  • OS: OSX High Sierra 10.13.3
  • Laravel Installer 1.5.0
  • Laravel Framework 5.6.16

Description:

On a fresh install, when I run npm run production, mix will not update the hash on app.js. The hash that is written appears not to change even though the file being compiled has changed.

Steps to Reproduce:

  • Install new Laravel project
  • Install Composer dependencies
  • Install Node Modules
  • npm run production to create initial mix-manifest
  • Add "In production" version conditional to webpack.mix.js
    if (mix.inProduction()) { mix.version(); }
  • Edit resources/scss/app.scss THEN npm run production

    • RESULT: The css hash in mix-manifest updates as expected

  • Edit resources/js/app.js THEN npm run production

    • RESULT: The js hash does not change

Most helpful comment

From what I gather it doesn't do webpack style hashing on JS files declared in your mix file when running npm run prod. Instead, it'll add an ?id= for each recognized asset in the mix file in the manifest.json. When using the mix() blade function, it'll take the file within the argument and find the respective entry in the manifest and then use that entry as the asset file.

If you you really want to add your own webpack style hashing on your JS, you will have to override the webpack config entry point to use [name].[yourhashofchoice].js

All 7 comments

Could not reproduce.
Are you making significant changes in app.js ?

@ankurk91 No, the changes were not extensive. Sample app js:

require('./bootstrap');

window.Vue = require('vue');

Vue.component('example-component', require('./components/ExampleComponent.vue'));

const app = new Vue({
    el: '#app'
});

var test='test';
var test2='test';
var test3='testing';
var testFuncton = function(){
    console.log('Test function');
}

It appears that the simple variables/functions I add at the bottom of the file do not trigger a hash update.

HOWEVER, I did notice that if I put them in a separate file and imported them (e.g. import './test.js'), it triggered a hash change.

Also, if I remove the Vue component or comment out the app const, the hash gets updated.

Curious if webpack/mix is smart enough to realize you're in production mode and those are unused variables and an unused function. Maybe it strips and ignores?

From what I gather it doesn't do webpack style hashing on JS files declared in your mix file when running npm run prod. Instead, it'll add an ?id= for each recognized asset in the mix file in the manifest.json. When using the mix() blade function, it'll take the file within the argument and find the respective entry in the manifest and then use that entry as the asset file.

If you you really want to add your own webpack style hashing on your JS, you will have to override the webpack config entry point to use [name].[yourhashofchoice].js

@ikudosi Thanks for your feedback. I'm going to close the issue as it's not really affecting me at the moment, and it doesn't seem like anyone else has noticed it.

I have this problem too. Is this all right now?

@heimuya My solution was to move notable changes to external files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pixieaka picture pixieaka  路  3Comments

hasnatbabur picture hasnatbabur  路  3Comments

kpilard picture kpilard  路  3Comments

dtheb picture dtheb  路  3Comments

mementoneli picture mementoneli  路  3Comments