gpt4 book ai didi

Webpack 工作箱在您的软件源中找不到 self.__WB_MANIFEST

转载 作者:行者123 更新时间:2023-12-04 11:36:26 40 4
gpt4 key购买 nike

我从 webpack-workbox-plugin 的 v4 迁移到 v5,但是当我尝试构建时,出现错误:

ERROR in Can't find self.__WB_MANIFEST in your SW source.
Child InjectManifest:
Asset Size Chunks Chunk Names
sw.js 1.5 KiB 0 [emitted] InjectManifest
Child html-webpack-plugin for "index.html":
1 asset

__WB_MANIFEST会在 precach-manifest 文件中创建并像 v4 一样自动导入吗?

网络包配置:

new WorkboxPlugin.InjectManifest({
swSrc: 'sw.js',
chunks: ['*.chunk.js'],
exclude: [/\.(?:png|jpg|jpeg|svg)$/, /\.map$/, /manifest\.json$/, /service-worker\.js$/, /sw\.js$/],
include: [path.resolve(process.cwd(), 'build')],
}),

我的 sw.js:


importScripts('./ChabokSDKWorker.js', 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js');

/* eslint-disable no-undef */

if (workbox) {
workbox.core.skipWaiting();
workbox.core.clientsClaim();
workbox.precaching.cleanupOutdatedCaches();

// eslint-disable-next-line no-restricted-globals,no-underscore-dangle
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);

// java-script files cache
workbox.routing.registerRoute(
new RegExp('.+\\.js$'),
workbox.strategies.StaleWhileRevalidate({
cacheName: 'js-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24 * 7,
purgeOnQuotaError: true,
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
],
}),
);

// css files cache
workbox.routing.registerRoute(
new RegExp('.+\\.css$'),
workbox.strategies.StaleWhileRevalidate({
cacheName: 'css-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 5,
maxAgeSeconds: 60 * 60 * 24 * 7,
purgeOnQuotaError: true,
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
],
}),
);

// image files cache
workbox.routing.registerRoute(
new RegExp('.+\\.(png|jpg|jpeg|svg)$'),
workbox.strategies.CacheFirst({
cacheName: 'images-cache',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24 * 7,
purgeOnQuotaError: true,
}),
new workbox.cacheableResponse.Plugin({
statuses: [0, 200],
}),
],
}),
);

workbox.routing.registerRoute(
new RegExp('/.*'),
workbox.strategies.NetworkFirst({}),
'GET',
);
} else {
console.log(`Boo! Workbox didn't load 😬`);
}
/* eslint-enable no-undef */

最佳答案

这是我针对injectManifest 错误的webpack 配置,我是这样修复的:

    new WorkboxPlugin.InjectManifest({
swSrc: path.join(process.cwd(), '/app/resources/service-worker.js'),
swDest: 'sw.js',
exclude: [
/\.map$/,
/manifest$/,
/\.htaccess$/,
/service-worker\.js$/,
/sw\.js$/,
],
}),

现在 self.__WB_MANIFEST将替换为预缓存文件列表

关于Webpack 工作箱在您的软件源中找不到 self.__WB_MANIFEST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60491114/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com