From ec0d836c599dcd270a7168b8b61a249d9335c09b Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 23 Jan 2023 19:16:16 +0000 Subject: [PATCH] fix: pwa config position --- next.config.js | 65 ++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/next.config.js b/next.config.js index e7a2f174..4d34e2ee 100644 --- a/next.config.js +++ b/next.config.js @@ -5,10 +5,43 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({ enabled: process.env.ANALYZE === "true", }) const execSync = require("child_process").execSync + +const cache = require("next-pwa/cache") const withPWA = require("next-pwa")({ dest: "public", + publicExcludes: ["*"], + runtimeCaching: [ + { + urlPattern: ({ url }) => { + return /\/ipfs\/([^/?#]+)$/.test(url.toString()) + }, + handler: "CacheFirst", + options: { + cacheName: "next-ipfs", + expiration: { + maxEntries: 64, + maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days + }, + cacheableResponse: { + statuses: [0, 200], + }, + }, + }, + { + urlPattern: /\/_next\/image\?url=.+%2Fipfs%2F([^/?#]+)$/i, + handler: "CacheFirst", + options: { + cacheName: "next-ipfs", + expiration: { + maxEntries: 64, + maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days + }, + }, + }, + // @ts-ignore + ...cache, + ], }) -const cache = require("next-pwa/cache") const lastCommitCommand = "git rev-parse HEAD" @@ -71,35 +104,5 @@ module.exports = withBundleAnalyzer( ENV_OPENSEA_API_KEY: process.env.OPENSEA_API_KEY, ENV_POAP_API_KEY: process.env.POAP_API_KEY, }, - - pwa: { - publicExcludes: ["*"], - dynamicStartUrl: true, - runtimeCaching: [ - { - urlPattern: /\/(ipfs)\/([^/?#]+)/i, - handler: "CacheFirst", - options: { - cacheName: "next-ipfs", - expiration: { - maxEntries: 64, - maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days - }, - }, - }, - { - urlPattern: /\/_next\/image\?url=.+%2Fipfs%2F([^/?#]+)$/i, - handler: "CacheFirst", - options: { - cacheName: "next-ipfs", - expiration: { - maxEntries: 64, - maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days - }, - }, - }, - ...cache, - ], - }, }), )