Jafo
Jafo

Reputation: 1331

Laravel Mix & Numbered Assets, Hash instead?

When I run npn run dev on my Laravel project I get:

enter image description here

Is there any way to change the name of these numbered javascript assets to something unique such as a hash based on contents? They don't seem to have a cache busting hash in the query string when being requested and I have noticed issues from time to time with browsers caching these. Here is my webpack.mix.js file:

let mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sass('resources/sass/web.scss', 'public/css/web.css')
.options({
  processCssUrls: false,

}).version();

mix.extract(['vue', 'jquery']);

Upvotes: 6

Views: 2285

Answers (1)

Jafo
Jafo

Reputation: 1331

This is what I eventually ended up doing and it works well:

mix.webpackConfig({
    output: {
        chunkFilename: "[name].[chunkhash:8].js",
        filename: "[name].js",
    }
});

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
   .sass('resources/sass/web.scss', 'public/css/web.css')
   .options({
      processCssUrls: false,

    }).version();

mix.extract(['vue', 'jquery']);

Upvotes: 8

Related Questions