This commit is contained in:
hackrobot
2025-03-26 18:25:50 -05:00
parent d94b011163
commit 7a74bc3c11
7 changed files with 2214 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
const { GenerateSW } = require("workbox-webpack-plugin");
const config = {
projectName: "cityh5",
@@ -44,6 +46,42 @@ const config = {
},
h5: {
webpackChain(chain) {
if (
process.env.NODE_ENV === "production" &&
!chain.plugins.has("workbox")
) {
chain.plugin("workbox").use(GenerateSW, [
{
clientsClaim: true,
skipWaiting: true,
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
runtimeCaching: [
{
urlPattern: /.*\.(?:png|jpg|jpeg|svg|gif|ico)/,
handler: "CacheFirst",
options: {
cacheName: "images-cache",
expiration: {
maxEntries: 50,
maxAgeSeconds: 30 * 24 * 60 * 60,
},
},
},
{
urlPattern: /.*\.(?:js|css)/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "static-resources",
expiration: {
maxEntries: 50,
maxAgeSeconds: 7 * 24 * 60 * 60,
},
},
},
],
},
]);
}
chain.module
.rule("markdown")
.test(/\.md$/)