Skip to content

Instantly share code, notes, and snippets.

@roelofjan-elsinga
Last active June 17, 2022 19:44
Show Gist options
  • Save roelofjan-elsinga/1504426161dbe1ae15014c946bd57f8b to your computer and use it in GitHub Desktop.
Save roelofjan-elsinga/1504426161dbe1ae15014c946bd57f8b to your computer and use it in GitHub Desktop.
Laravel Mix Workbox example
const mix = require('laravel-mix');
// Import the workbox plugin
require('laravel-mix-workbox');
mix
// ... js, scss, and other rules
// webpackConfig is important here
.webpackConfig({
output: { publicPath: '' }
})
.generateSW({
// Set the path to the sw.js file
swDest: path.join(`${__dirname}/public`, 'sw.js'),
// Do not precache images
exclude: [
/\.(?:png|jpg|jpeg|svg)$/,
// Ignore the mix.js that's being generated
'mix.js'
],
// Define runtime caching rules.
runtimeCaching: [
{
// Match any request that ends with .png, .jpg, .jpeg or .svg.
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
// Apply a cache-first strategy.
handler: 'CacheFirst',
options: {
// Use a custom cache name.
cacheName: 'images',
},
}
],
clientsClaim: true,
skipWaiting: true
});
@uacode
Copy link

uacode commented Jun 17, 2022

Thanks for "Ignore the mix.js". Two hours for searching it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment