From ecc1fe7e4b27ef22691e9930736552468f6dfbb9 Mon Sep 17 00:00:00 2001 From: DuCanhGH <75556609+DuCanhGH@users.noreply.github.com> Date: Sat, 28 Jan 2023 15:27:16 +0700 Subject: [PATCH] fix(core): fixed user's webpack config being overridden if the plugin is disabled [bump ver] --- .changeset/brave-bananas-melt.md | 19 +++++++++++++++++++ packages/next-pwa/src/index.ts | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .changeset/brave-bananas-melt.md diff --git a/.changeset/brave-bananas-melt.md b/.changeset/brave-bananas-melt.md new file mode 100644 index 00000000..97308c18 --- /dev/null +++ b/.changeset/brave-bananas-melt.md @@ -0,0 +1,19 @@ +--- +"@ducanh2912/next-pwa": patch +--- + +fix(core): fixed user's webpack config being overridden if the plugin is disabled + +- Before this patch, the plugin used to override user-defined or other plugins' Webpack custom config because it early returned the config (without calling `nextConfig.webpack?.()`) if it was disabled. This fixes it by calling `nextConfig.webpack?.()` before doing anything else. + +chore(types): changed `compilerOptions.moduleResolution` to `"nodeNext"`. + +- This shouldn't impact users. It is only meant to force me to write `.js` at the end of import paths and stuff. + +docs(README): refined main README.md + +- Rewrote README.md to fix grammar issues and decouple tips into TIPS.md. I also fixed/removed some broken links. + +chore(deps): ran deps:update-all + +- Nothing too special... diff --git a/packages/next-pwa/src/index.ts b/packages/next-pwa/src/index.ts index ccc8dd18..a6e526d9 100644 --- a/packages/next-pwa/src/index.ts +++ b/packages/next-pwa/src/index.ts @@ -75,6 +75,10 @@ const withPWAInit = ( ...workbox } = workboxOptions; + if (typeof nextConfig.webpack === "function") { + config = nextConfig.webpack(config, options); + } + Object.keys(workbox).forEach( (key) => workbox[key as keyof typeof workbox] === undefined && @@ -451,9 +455,6 @@ const withPWAInit = ( config.plugins.push(workboxPlugin); } } - if (typeof nextConfig.webpack === "function") { - return nextConfig.webpack(config, options); - } return config; }, } as NextConfig),