增加serviceWork
Others 2023-07-21 07:13:41 2023-07-21 07:13:41 10 次浏览import { GenerateSW } from 'workbox-webpack-plugin';
export const swScript = ` if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/wmpc/service-worker.js').then(registration => { console.log('SW registered: ', registration); }).catch(registrationError => { console.log('SW registration failed: ', registrationError); }); }); } `;export function generalWorkBoxConfig(config) { config.plugin('WorkboxPlugin').use(GenerateSW, [ { cacheId: 'wmpc-sw', clientsClaim: true, skipWaiting: true, maximumFileSizeToCacheInBytes: 1, cleanupOutdatedCaches: true, additionalManifestEntries: [cdnFileSrc], runtimeCaching: [ { urlPattern: ({ request }) => { const domain = new URL(request.url).host .split('.') .slice(-2) .join('.'); return domain === 'lininn.cn' && ['script', 'image', 'style'].includes(request.destination); }, handler: 'StaleWhileRevalidate' } ] } ]); }
chainWebpack: (config) => { generalWorkBoxConfig(config); },
<div style="background-color:#FFFFFF;font-family:Menlo, Monaco, "font-size:15px;line-height:23px;white-space-collapse:preserve;">
headScripts: [swScript]
</div>
</p>
</p>
Links: 585