laravel-mix: mix.version() is not working (no hashes are added in mix-manifest.json)

  • Laravel Mix Version: 1.4.2
  • Node Version (node -v): v6.10.3
  • NPM Version (npm -v): 3.10.10
  • OS: Centos + MacOS

Description:

mix.version() is not generating hashed URL’s for my assets

Steps To Reproduce:

in my webpack.mix.js I have:

if (mix.inProduction()) {
    console.log("We are in production");
    mix.version(['public/js/app.js', 'public/css/app.css']);
}

the console log gets triggered just fine, but there are no hashes appended to my stylesheet or js file, which I’m loading in my views like so:

<link href="{{ mix('css/app.css') }}" rel="stylesheet"> the output is the following without cache busting: <link href="/css/app.css" rel="stylesheet">

the mix-manifest.json file looks like this

{
    "/js/app.js": "/js/app.js",
    "/css/app.css": "/css/app.css",
    "/js/app.js.map": "/js/app.js.map",
    "/css/app.css.map": "/css/app.css.map"
}

UPDATE: this seems to be working locally on my machine, but not on my CentOS server. I’ve set permissions to 777 on the mix-manifest.json file, but that doesn’t solve the issue. I’m thinking this might be permission related? Are there any other files that mix needs to be able to write to while running the build in order to update the mix-manifest file?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 27

Most upvoted comments

I found out that the mix configuration parameter “inProduction” has been rename to “production”. I’m using the below code for versioning.

if (mix.config.production) {
    mix.version();
}

The final JS file with hash mappings are stored in the mix-manifest.json file.

I was really stuck here for a while. If nothing above seems to work, it’s possible you’ve made the same mistake I did. Make sure you are calling mix and not asset when you include your script. Good: <script src="{{ mix('js/app.js') }}" defer></script> Bad: <script src="{{ asset('js/app.js') }}" defer></script>

It would be awesome to opt in to the ‘old’ way of versioning if needed (i.e. filename versioning instead of query-string versioning). Is this functionality something you’d consider supporting in Laravel Mix?

One example use-case is that I use S3/CDNs and load-balancing on my site. I require that an old version of a file still remains on the CDN (S3) while the new version is uploaded/exists. An example scenario: I’ve very recently deployed a new release for my webapp - with some newly compiled javascript/css. While this release is being deployed to all the servers behind load balancers, someone requests a webpage. The load balancer then serves up the HTML from an old server via the load balancer that hasn’t yet been updated with the latest release (and the new javascript version for app.js). With filename versioning, this isn’t an issue, because this old server is using the old mix-manifest.js with the old version-hashed filename (e.g. app.abc123.js). So, the browser ends up correctly downloading the old file (app.abc123.js). Concurrently, other website visitors are hitting the servers with the latest release (via the load-balancer), and therefore being told to download the new javascript file from S3 (app.def456.js). All is well here…

Unfortunately, with query string versioning, requesting app.js?id=def456 and app.js?id=abc123.js from S3 will return the same file - the new one (version def456), and so the webapp breaks. 😩

This is just one scenario, but if not convinced, I can try explain another. I don’t think there’s a right way to version it per se, more just that in certain circumstances, file versioning is preferred over querystring versioning.

Thoughts?

This issue is still not resolved mix.version(); doesn’t do anything

Seems to be a fairly old thread now but I had the same issue and I managed to fix it by updating node_modules/laravel-mix/src/config.js.

I changed the versioning property from false to true, added mix.version() to my webpack.mix.js file, then everything worked as expected 🕺

The versioning property has been removed from Laravel 5.6 onward, I must have been using an old version of Laravel when I posted this.

Actually I first thought that the version was still being appended to the filename and after reviewing the master branch history I figured the version is now inside mix-manifest.json, which I should have opened sooner, in a commit that reads “refactoring”… Anyways, in my case it was a big confusion (albeit the fact I didn’t find a doc telling me how the versioning works…)

This worked for me (version "laravel-mix": "0.*"):

if (mix.config.inProduction) {
  mix.version();
}