Last active
June 17, 2022 19:44
-
-
Save roelofjan-elsinga/1504426161dbe1ae15014c946bd57f8b to your computer and use it in GitHub Desktop.
Laravel Mix Workbox example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for "Ignore the mix.js". Two hours for searching it :)