Skip to content

Commit

Permalink
inject manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardZaydler committed Oct 16, 2024
1 parent 242bdb2 commit def5e59
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
18 changes: 18 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { precacheAndRoute } from "workbox-precaching/precacheAndRoute";

precacheAndRoute(self.__WB_MANIFEST);

// interface CustomFetchEvent extends Event {
// request: Request;
// respondWith(response: Promise<Response> | Response): void;
// }

self.addEventListener("fetch", (event) => {
console.log("Fetch event triggered");

const fetchEvent = event;
const url = fetchEvent.request.url;
if (url.includes("oauth")) {
fetchEvent.respondWith(fetch(fetchEvent.request));
}
});
9 changes: 0 additions & 9 deletions src/sw.js

This file was deleted.

28 changes: 15 additions & 13 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ContextReplacementPlugin = webpack.ContextReplacementPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const { GenerateSW } = require("workbox-webpack-plugin");
const { InjectManifest } = require("workbox-webpack-plugin");
const supportedLocales = ["en"];

const isDev = process.argv.includes("--mode=development");
Expand All @@ -21,18 +21,20 @@ module.exports = {
clean: true,
},
plugins: [
!isDev &&
new GenerateSW({
//https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin#type-GenerateSW
// default maximum size is 3mb while our main chunk is 4mb
// that's why size is sincreased to 6mb
maximumFileSizeToCacheInBytes: 6291456,
cleanupOutdatedCaches: true,
clientsClaim: true,
sourcemap: false,
skipWaiting: true,
importScripts: ["/sw.js"],
}),
// !isDev &&
new InjectManifest({
//https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin#type-GenerateSW
// default maximum size is 3mb while our main chunk is 4mb
// that's why size is sincreased to 6mb

maximumFileSizeToCacheInBytes: 6291456,
// cleanupOutdatedCaches: true,
// clientsClaim: true,
// sourcemap: false,
// skipWaiting: true,
swSrc: "/service-worker.js",
swDest: "service-worker.js",
}),
new ContextReplacementPlugin(
/date-fns[\/\\]/,
new RegExp(`[/\\\\\](${supportedLocales.join("|")})[/\\\\\]`)
Expand Down

0 comments on commit def5e59

Please sign in to comment.