From 86f590a10957dca79aa30eb65f380adf02e868bd Mon Sep 17 00:00:00 2001 From: Marcos Iglesias Date: Sun, 3 Sep 2023 22:28:47 -0300 Subject: [PATCH] feat: nextjs plugins --- apps/website-ssr/public/sw.js | 2 +- package.json | 4 +++- packages/next-config/nextpwa.config.js | 25 +++++++++++++++++++------ packages/next-config/package.json | 1 + pnpm-lock.yaml | 18 ++++++++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/apps/website-ssr/public/sw.js b/apps/website-ssr/public/sw.js index c170d39..6e4d13e 100644 --- a/apps/website-ssr/public/sw.js +++ b/apps/website-ssr/public/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const n=(n,a)=>(n=new URL(n+".js",a).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(a,i)=>{const c=e||("document"in self?document.currentScript.src:"")||location.href;if(s[c])return;let t={};const o=e=>n(e,c),r={module:{uri:c},exports:t,require:o};s[c]=Promise.all(a.map((e=>r[e]||o(e)))).then((e=>(i(...e),t)))}}define(["./workbox-8c8aeaed"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/static/chunks/framework-0f8888d1cd333966.js",revision:"0f8888d1cd333966"},{url:"/_next/static/chunks/main-718c5a75e4d334bb.js",revision:"718c5a75e4d334bb"},{url:"/_next/static/chunks/pages/404-9bf31a9d7d6ffe09.js",revision:"9bf31a9d7d6ffe09"},{url:"/_next/static/chunks/pages/DemoSSR-72a70aa4e999d9d5.js",revision:"72a70aa4e999d9d5"},{url:"/_next/static/chunks/pages/_app-f0a0b370653d1ea1.js",revision:"f0a0b370653d1ea1"},{url:"/_next/static/chunks/pages/_error-924c3a8f78a5d1e8.js",revision:"924c3a8f78a5d1e8"},{url:"/_next/static/chunks/pages/index-8b9d0f75cf1f1949.js",revision:"8b9d0f75cf1f1949"},{url:"/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js",revision:"79330112775102f91e1010318bae2bd3"},{url:"/_next/static/chunks/webpack-8fa1640cc84ba8fe.js",revision:"8fa1640cc84ba8fe"},{url:"/_next/static/css/a064722aa83e9cc8.css",revision:"a064722aa83e9cc8"},{url:"/_next/static/x9daquH1AQJfjd47K9oIU/_buildManifest.js",revision:"6ec61996a6fc5f3c66d326b9680adfb5"},{url:"/_next/static/x9daquH1AQJfjd47K9oIU/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/android-chrome-192x192.png",revision:"b40b9799619c0fa0808d8270084741f9"},{url:"/android-chrome-512x512.png",revision:"5d231b9497d8e006095e889564624771"},{url:"/apple-touch-icon.png",revision:"5a43bee0c7f9fe0fbb441f4030c29004"},{url:"/favicon-16x16.png",revision:"ef99ba6888b371af7c57cd6a9e076a87"},{url:"/favicon-32x32.png",revision:"6f3b2403df7f7fb3acb6682fb9cdf84a"},{url:"/favicon.ico",revision:"88e2cc4585963c8eef22072457bc6589"},{url:"/icon-192x192.png",revision:"662bcbc3774cb22d27d1ea432f5dd82c"},{url:"/icon-256x256.png",revision:"5e57e07bfa3065b27494ccf1f59bf8c4"},{url:"/icon-384x384.png",revision:"9f5820b98c540d9368dbad764c5ac966"},{url:"/icon-512x512.png",revision:"8ed4a712e852a438cb951b28dc70008e"},{url:"/manifest.json",revision:"6fc62454361d79958dbf5c51a907e94d"},{url:"/maskable_icon.png",revision:"9554c211141fc92229b83790fda2be4d"},{url:"/maskable_icon_x48.png",revision:"8ebe5c753ae8d2069b2a082ebeacff8e"},{url:"/site.webmanifest",revision:"053100cb84a50d2ae7f5492f7dd7f25e"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaches(),e.registerRoute("/",new e.NetworkFirst({cacheName:"start-url",plugins:[{cacheWillUpdate:async({request:e,response:s,event:n,state:a})=>s&&"opaqueredirect"===s.type?new Response(s.body,{status:200,statusText:"OK",headers:s.headers}):s}]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,new e.CacheFirst({cacheName:"google-fonts-webfonts",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:31536e3})]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,new e.StaleWhileRevalidate({cacheName:"google-fonts-stylesheets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,new e.StaleWhileRevalidate({cacheName:"static-font-assets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,new e.StaleWhileRevalidate({cacheName:"static-image-assets",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/image\?url=.+$/i,new e.StaleWhileRevalidate({cacheName:"next-image",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp3|wav|ogg)$/i,new e.CacheFirst({cacheName:"static-audio-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp4)$/i,new e.CacheFirst({cacheName:"static-video-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:js)$/i,new e.StaleWhileRevalidate({cacheName:"static-js-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:css|less)$/i,new e.StaleWhileRevalidate({cacheName:"static-style-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/data\/.+\/.+\.json$/i,new e.StaleWhileRevalidate({cacheName:"next-data",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:json|xml|csv)$/i,new e.NetworkFirst({cacheName:"static-data-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;const s=e.pathname;return!s.startsWith("/api/auth/")&&!!s.startsWith("/api/")}),new e.NetworkFirst({cacheName:"apis",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:16,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;return!e.pathname.startsWith("/api/")}),new e.NetworkFirst({cacheName:"others",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>!(self.origin===e.origin)),new e.NetworkFirst({cacheName:"cross-origin",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:3600})]}),"GET")})); +if(!self.define){let e,s={};const n=(n,a)=>(n=new URL(n+".js",a).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(a,i)=>{const c=e||("document"in self?document.currentScript.src:"")||location.href;if(s[c])return;let t={};const o=e=>n(e,c),r={module:{uri:c},exports:t,require:o};s[c]=Promise.all(a.map((e=>r[e]||o(e)))).then((e=>(i(...e),t)))}}define(["./workbox-8c8aeaed"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/static/XqduK89_4lNZQJJmt-UHy/_buildManifest.js",revision:"6ec61996a6fc5f3c66d326b9680adfb5"},{url:"/_next/static/XqduK89_4lNZQJJmt-UHy/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/_next/static/chunks/framework-0f8888d1cd333966.js",revision:"0f8888d1cd333966"},{url:"/_next/static/chunks/main-bc98a3f10804c490.js",revision:"bc98a3f10804c490"},{url:"/_next/static/chunks/pages/404-9bf31a9d7d6ffe09.js",revision:"9bf31a9d7d6ffe09"},{url:"/_next/static/chunks/pages/DemoSSR-72a70aa4e999d9d5.js",revision:"72a70aa4e999d9d5"},{url:"/_next/static/chunks/pages/_app-f0a0b370653d1ea1.js",revision:"f0a0b370653d1ea1"},{url:"/_next/static/chunks/pages/_error-924c3a8f78a5d1e8.js",revision:"924c3a8f78a5d1e8"},{url:"/_next/static/chunks/pages/index-8b9d0f75cf1f1949.js",revision:"8b9d0f75cf1f1949"},{url:"/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js",revision:"79330112775102f91e1010318bae2bd3"},{url:"/_next/static/chunks/webpack-8fa1640cc84ba8fe.js",revision:"8fa1640cc84ba8fe"},{url:"/_next/static/css/a064722aa83e9cc8.css",revision:"a064722aa83e9cc8"},{url:"/android-chrome-192x192.png",revision:"b40b9799619c0fa0808d8270084741f9"},{url:"/android-chrome-512x512.png",revision:"5d231b9497d8e006095e889564624771"},{url:"/apple-touch-icon.png",revision:"5a43bee0c7f9fe0fbb441f4030c29004"},{url:"/favicon-16x16.png",revision:"ef99ba6888b371af7c57cd6a9e076a87"},{url:"/favicon-32x32.png",revision:"6f3b2403df7f7fb3acb6682fb9cdf84a"},{url:"/favicon.ico",revision:"88e2cc4585963c8eef22072457bc6589"},{url:"/icon-192x192.png",revision:"662bcbc3774cb22d27d1ea432f5dd82c"},{url:"/icon-256x256.png",revision:"5e57e07bfa3065b27494ccf1f59bf8c4"},{url:"/icon-384x384.png",revision:"9f5820b98c540d9368dbad764c5ac966"},{url:"/icon-512x512.png",revision:"8ed4a712e852a438cb951b28dc70008e"},{url:"/manifest.json",revision:"6fc62454361d79958dbf5c51a907e94d"},{url:"/maskable_icon.png",revision:"9554c211141fc92229b83790fda2be4d"},{url:"/maskable_icon_x48.png",revision:"8ebe5c753ae8d2069b2a082ebeacff8e"},{url:"/site.webmanifest",revision:"8fffcdf720e62d5b464f43d965beff3d"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaches(),e.registerRoute("/",new e.NetworkFirst({cacheName:"start-url",plugins:[{cacheWillUpdate:async({request:e,response:s,event:n,state:a})=>s&&"opaqueredirect"===s.type?new Response(s.body,{status:200,statusText:"OK",headers:s.headers}):s}]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,new e.CacheFirst({cacheName:"google-fonts-webfonts",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:31536e3})]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,new e.StaleWhileRevalidate({cacheName:"google-fonts-stylesheets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,new e.StaleWhileRevalidate({cacheName:"static-font-assets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,new e.StaleWhileRevalidate({cacheName:"static-image-assets",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/image\?url=.+$/i,new e.StaleWhileRevalidate({cacheName:"next-image",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp3|wav|ogg)$/i,new e.CacheFirst({cacheName:"static-audio-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp4)$/i,new e.CacheFirst({cacheName:"static-video-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:js)$/i,new e.StaleWhileRevalidate({cacheName:"static-js-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:css|less)$/i,new e.StaleWhileRevalidate({cacheName:"static-style-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/data\/.+\/.+\.json$/i,new e.StaleWhileRevalidate({cacheName:"next-data",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:json|xml|csv)$/i,new e.NetworkFirst({cacheName:"static-data-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;const s=e.pathname;return!s.startsWith("/api/auth/")&&!!s.startsWith("/api/")}),new e.NetworkFirst({cacheName:"apis",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:16,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;return!e.pathname.startsWith("/api/")}),new e.NetworkFirst({cacheName:"others",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>!(self.origin===e.origin)),new e.NetworkFirst({cacheName:"cross-origin",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:3600})]}),"GET")})); diff --git a/package.json b/package.json index 51404cb..9d59279 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "fix:eslint": "eslint --fix .", "fix:prettier": "prettier --plugin-search-dir=. --write .", "fix": "run-s fix:*", - "prepare": "husky install" + "prepare": "husky install", + "analyze": "cross-env ANALYZE=true pnpm build" }, "lint-staged": { "*": "prettier --ignore-unknown --write", @@ -42,6 +43,7 @@ "@types/react": "18.2.16", "@types/react-dom": "18.2.7", "@types/testing-library__jest-dom": "5.14.9", + "cross-env": "^7.0.3", "eslint": "8.45.0", "eslint-config-custom": "workspace:*", "husky": "8.0.3", diff --git a/packages/next-config/nextpwa.config.js b/packages/next-config/nextpwa.config.js index 5af760d..098e4f6 100644 --- a/packages/next-config/nextpwa.config.js +++ b/packages/next-config/nextpwa.config.js @@ -1,11 +1,14 @@ -// const withBundleAnalyzer = require("@next/bundle-analyzer")({ +const withPlugins = require("next-compose-plugins"); +const withBundleAnalyzer = require("@next/bundle-analyzer"); +// ({ // enabled: !!process.env.ANALYZE, // }); -const withPWA = require("next-pwa")({ - dest: "public", - disable: process.env.NODE_ENV === "development", -}); +const withPWA = require("next-pwa"); +// ({ +// dest: "public", +// disable: process.env.NODE_ENV === "development", +// }); module.exports = ({ basePath }) => { /** @type {import('next').NextConfig} */ @@ -16,5 +19,15 @@ module.exports = ({ basePath }) => { transpilePackages: ["ui", "utils"], }; - return withPWA(config); + return withPlugins( + [ + [withBundleAnalyzer({ enabled: process.env.ANALYZE })], + withPWA({ + dest: "public", + disable: process.env.NODE_ENV === "development", + }), + ], + config, + ); + // return withPWA(config); }; diff --git a/packages/next-config/package.json b/packages/next-config/package.json index 9498193..3b0e5aa 100644 --- a/packages/next-config/package.json +++ b/packages/next-config/package.json @@ -4,6 +4,7 @@ "version": "0.0.0", "devDependencies": { "@next/bundle-analyzer": "13.4.12", + "next-compose-plugins": "^2.2.1", "next-pwa": "^5.6.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5486567..4726aa1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: '@types/testing-library__jest-dom': specifier: 5.14.9 version: 5.14.9 + cross-env: + specifier: ^7.0.3 + version: 7.0.3 eslint: specifier: 8.45.0 version: 8.45.0 @@ -234,6 +237,9 @@ importers: '@next/bundle-analyzer': specifier: 13.4.12 version: 13.4.12 + next-compose-plugins: + specifier: ^2.2.1 + version: 2.2.1 next-pwa: specifier: ^5.6.0 version: 5.6.0(@babel/core@7.22.9)(esbuild@0.18.16)(next@13.4.12)(webpack@5.88.2) @@ -6152,6 +6158,14 @@ packages: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} dev: true + /cross-env@7.0.3: + resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} + engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} + hasBin: true + dependencies: + cross-spawn: 7.0.3 + dev: true + /cross-spawn@6.0.5: resolution: {integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==} engines: {node: '>=4.8'} @@ -9886,6 +9900,10 @@ packages: resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==} dev: true + /next-compose-plugins@2.2.1: + resolution: {integrity: sha512-OjJ+fV15FXO2uQXQagLD4C0abYErBjyjE0I0FHpOEIB8upw0hg1ldFP6cqHTJBH1cZqy96OeR3u1dJ+Ez2D4Bg==} + dev: true + /next-pwa@5.6.0(@babel/core@7.22.9)(esbuild@0.18.16)(next@13.4.12)(webpack@5.88.2): resolution: {integrity: sha512-XV8g8C6B7UmViXU8askMEYhWwQ4qc/XqJGnexbLV68hzKaGHZDMtHsm2TNxFcbR7+ypVuth/wwpiIlMwpRJJ5A==} peerDependencies: