【发布时间】:2018-11-08 09:56:59
【问题描述】:
我有关于 workbox 和 create-react-app v2 的问题。 我用workbox-build生成自定义service worker,注入有问题
const backgroundSync = new workbox.backgroundSync.Plugin('ticketsQueue', {
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours
});
const buildSW = () =>
workboxBuild.generateSW({
globDirectory: 'build',
// importWorkboxFrom: 'local',
globPatterns: ['**/*.{json,ico,html,js,css,woff2,woff,png,svg}'],
globIgnores: ['asset-manifest.json'],
skipWaiting: true,
clientsClaim: true,
swDest: 'build/sw.js',
navigateFallback: 'index.html',
directoryIndex: 'index.html',
runtimeCaching: [
{
urlPattern: new RegExp(`^${apiUrl}/tickets/create`),
handler: 'networkOnly',
options: {
plugins: [
backgroundSync
]
},
method: 'POST'
},
]
});
buildSW();
当我尝试使用 nodejs 执行 buildSW() 时,它会给出参考错误。 ReferenceError:未定义工作箱 如何包含它?或者还有其他方法吗? 谢谢
【问题讨论】:
标签: node.js service-worker create-react-app progressive-web-apps workbox