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uB,MAAM,QAAQ,GAoBpB,iBAAV,EAEhB,EAAS,QAAQ,MAAQ,CAAC,EAAO,GACxB,MAAM,QAAQ,IAEvB,EAAS,QAAQ,MAAM,KAAK,GArB5B,OAAO,KAAK,GAAO,SAAS,IAC1B,MAAM,EAAa,EAAM,GAIvB,GACA,EAAW,QACX,MAAM,QAAQ,EAAW,QAEzB,EAAW,OAAO,KAAK,GACd,MAAM,QAAQ,GACvB,EAAM,GAAK,KAAK,GACe,iBAAf,IAChB,EAAM,GAAO,CAAC,EAAY,GAC5B,GAQJ,GAIJ,EAGF,OAAO,QAAU","file":"/npm/webpack-pwa-sw-plugin@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/webpack-pwa-sw-plugin@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const { InjectManifest } = require(\"workbox-webpack-plugin\");\r\nconst VirtualModulesPlugin = require(\"webpack-virtual-modules\");\r\nconst path = require(\"path\");\r\nconst webpack = require(\"webpack\");\r\n\r\nclass WebpackPwaSwPlugin {\r\n  constructor(options = {}) {\r\n    this.options = options;\r\n    this.virtualModules = new VirtualModulesPlugin();\r\n  }\r\n\r\n  generateServiceWorker(version) {\r\n    return `\r\n      import { clientsClaim } from 'workbox-core';\r\n      import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching';\r\n      import { setupRuntimeCaching, expectedCaches } from './runtimeCaching';\r\n\r\n      const manifest = self.__WB_MANIFEST;\r\n      clientsClaim();\r\n\r\n      cleanupOutdatedCaches();\r\n      precacheAndRoute(manifest);\r\n\r\n      self.addEventListener('message', (event) => {\r\n        if (event.data && event.data.type === 'SKIP_WAITING') {\r\n          //console.log('new service worker requested skip:');\r\n          setTimeout(() => self.skipWaiting(), 400);\r\n        }\r\n      });\r\n\r\n      self.addEventListener('install', (event) => {\r\n        //console.log('service worker installed:');\r\n      });\r\n\r\n      self.addEventListener('activate', (event) => {\r\n        event.waitUntil(\r\n          caches.keys().then((keys) => \r\n            Promise.all(keys.map((key) => {\r\n              if (!expectedCaches('${\r\n                version || 0\r\n              }').includes(key) && !key.includes('workbox-precache')) {\r\n                return caches.delete(key);\r\n              }\r\n            }))\r\n          ).then(() => {\r\n            //console.log('SW now ready to handle fetches!');\r\n          })\r\n        );\r\n      });\r\n\r\n      setupRuntimeCaching('${version || 0}', ${\r\n      this.options?.runtimeCaching\r\n        ? JSON.stringify(this.options?.runtimeCaching)\r\n        : '\"\"'\r\n    });\r\n    `;\r\n  }\r\n\r\n  apply(compiler) {\r\n    const packageJsonPath = path.resolve(compiler.context, \"package.json\");\r\n    const packageJson = require(packageJsonPath);\r\n    const version = packageJson.version;\r\n    if (this.options?.manifest) {\r\n      compiler.hooks.emit.tapAsync(\r\n        \"WebpackPwaSwPlugin\",\r\n        (compilation, callback) => {\r\n          const manifest = {\r\n            ...this.options?.manifest,\r\n          };\r\n\r\n          const manifestJson = JSON.stringify(manifest, null, 2);\r\n          compilation.assets[\"manifest.json\"] = {\r\n            source: () => manifestJson,\r\n            size: () => manifestJson.length,\r\n          };\r\n\r\n          callback();\r\n        }\r\n      );\r\n    }\r\n    // Generate the service worker code as a virtual module\r\n    compiler.hooks.beforeCompile.tap(\"WebpackPwaSwPlugin\", () => {\r\n      const serviceWorkerContent = this.generateServiceWorker(version);\r\n      this.virtualModules.writeModule(\r\n        path.resolve(__dirname, \"virtual-service-worker.js\"),\r\n        serviceWorkerContent\r\n      );\r\n      //console.log('Virtual service worker module written.'); // Debugging line\r\n    });\r\n\r\n    // Apply the virtual modules and InjectManifest plugin\r\n    this.virtualModules.apply(compiler);\r\n    new InjectManifest({\r\n      swSrc: path.resolve(__dirname, \"virtual-service-worker.js\"),\r\n      swDest: \"service-worker.js\",\r\n      maximumFileSizeToCacheInBytes: 15000000,\r\n      exclude: [\r\n        /manifest\\.json$/,\r\n        /\\.(map|bcmap|png|jpg|jpeg|gif|webp|svg|txt|json)$/,\r\n        /(well-known|googleapis|cmaps)/,\r\n      ],\r\n      ...(this.options?.workboxOptions || {}),\r\n    }).apply(compiler);\r\n\r\n    // Inject options via DefinePlugin\r\n    compiler.options.plugins.push(\r\n      new webpack.DefinePlugin({\r\n        WEBPACK_PWA_SW_PLUGIN_OPTIONS: JSON.stringify(this.options),\r\n      })\r\n    );\r\n    const serviceWorkerRegistrationPath = path.resolve(\r\n      __dirname,\r\n      \"serviceWorkerRegistration.js\"\r\n    );\r\n\r\n    compiler.hooks.entryOption.tap(\"WebpackPwaSwPlugin\", (context, entry) => {\r\n      //console.log('Original entry:', entry);\r\n\r\n      if (typeof entry === \"object\" && !Array.isArray(entry)) {\r\n        //console.log('Entry is an object:', entry);\r\n\r\n        // Iterate over each key in the entry object\r\n        Object.keys(entry).forEach((key) => {\r\n          const entryValue = entry[key];\r\n\r\n          // Check if entry[key] has an `import` array\r\n          if (\r\n            entryValue &&\r\n            entryValue.import &&\r\n            Array.isArray(entryValue.import)\r\n          ) {\r\n            entryValue.import.push(serviceWorkerRegistrationPath);\r\n          } else if (Array.isArray(entryValue)) {\r\n            entry[key].push(serviceWorkerRegistrationPath);\r\n          } else if (typeof entryValue === \"string\") {\r\n            entry[key] = [entryValue, serviceWorkerRegistrationPath];\r\n          }\r\n        });\r\n      } else if (typeof entry === \"string\") {\r\n        //console.log('Entry is a string:', entry);\r\n        compiler.options.entry = [entry, serviceWorkerRegistrationPath];\r\n      } else if (Array.isArray(entry)) {\r\n        //console.log('Entry is an array:', entry);\r\n        compiler.options.entry.push(serviceWorkerRegistrationPath);\r\n      }\r\n\r\n      //console.log('Modified entry:', compiler.options.entry);\r\n    });\r\n  }\r\n}\r\n\r\nmodule.exports = WebpackPwaSwPlugin;\r\n"]}