Skip to content

Commit

Permalink
generate sw
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardZaydler committed Oct 16, 2024
1 parent a8c9478 commit 6711f36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
22 changes: 0 additions & 22 deletions service-worker.js

This file was deleted.

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

const supportedLocales = ["en"];

const isDev = process.argv.includes("--mode=development");
Expand All @@ -21,16 +22,31 @@ module.exports = {
clean: true,
},
plugins: [
// !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
!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,
exclude: ["index.html", "**/oauth**"],
runtimeCaching: [
{
urlPattern: ({ request }) =>
request.mode === "navigate" ||
(request.headers.get("accept")?.includes("text/html") &&
!request.url.includes("oauth")),

maximumFileSizeToCacheInBytes: 6291456,
swSrc: "/service-worker.js",
swDest: "service-worker.js",
}),
handler: "NetworkFirst",
options: {
cacheName: "html-pages",
},
},
],
}),
new ContextReplacementPlugin(
/date-fns[\/\\]/,
new RegExp(`[/\\\\\](${supportedLocales.join("|")})[/\\\\\]`)
Expand Down

0 comments on commit 6711f36

Please sign in to comment.