From 11d5f3b67811779d9caec24d62acfdb9715b128a Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Fri, 19 Nov 2021 10:49:35 -0600 Subject: [PATCH 1/2] Fix/sw src (#1618) --- .changeset/sixty-badgers-dance.md | 5 +++++ packages/cli/lib/lib/webpack/webpack-client-config.js | 2 +- packages/cli/package.json | 2 +- yarn.lock | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/sixty-badgers-dance.md diff --git a/.changeset/sixty-badgers-dance.md b/.changeset/sixty-badgers-dance.md new file mode 100644 index 000000000..fa636a45f --- /dev/null +++ b/.changeset/sixty-badgers-dance.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Corrects error when `src/sw.js` does not exist and esm is disabled diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index 0d793b6a7..ae472f653 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -66,7 +66,7 @@ async function clientConfig(env) { ] : [ new InjectManifest({ - swSrc: join(src, 'sw.js'), + swSrc: swPath, include: [ /200\.html$/, /\.js$/, diff --git a/packages/cli/package.json b/packages/cli/package.json index 1b74850b9..b4bb6b8f2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -127,7 +127,7 @@ "stack-trace": "0.0.10", "style-loader": "^2.0.0", "terser-webpack-plugin": "^4.2.3", - "typescript": "^4.2.4", + "typescript": "~4.2.4", "update-notifier": "^5.1.0", "url-loader": "^4.1.1", "validate-npm-package-name": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index d1130eaf1..084624ebf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14431,7 +14431,7 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.2.4: +typescript@~4.2.4: version "4.2.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961" integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg== From 9039ba2e18bf1bf21b76425562617ad46e9d1d7c Mon Sep 17 00:00:00 2001 From: Ryan Christian <33403762+rschristian@users.noreply.github.com> Date: Sun, 21 Nov 2021 07:36:26 -0600 Subject: [PATCH 2/2] Fix/non esm sw generation (#1619) * fix: Correcting non-esm sw generation * docs: Adding changeset * fix: Bad merge Co-authored-by: Leah --- .changeset/seven-lions-cough.md | 5 ++ .../lib/lib/webpack/webpack-client-config.js | 58 +++++++++---------- 2 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 .changeset/seven-lions-cough.md diff --git a/.changeset/seven-lions-cough.md b/.changeset/seven-lions-cough.md new file mode 100644 index 000000000..c98acc631 --- /dev/null +++ b/.changeset/seven-lions-cough.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Fixing legacy SW generation while ESM is enabled diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index ae472f653..803b2fc61 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -46,36 +46,34 @@ async function clientConfig(env) { } else { warn(`Could not find sw.js in ${src}. Using the default service worker.`); } - swInjectManifest = env.esm - ? [ - new InjectManifest({ - swSrc: swPath, - swDest: 'sw-esm.js', - include: [ - /200\.html$/, - /\.esm.js$/, - /\.css$/, - /\.(png|jpg|svg|gif|webp)$/, - ], - webpackCompilationPlugins: [ - new webpack.DefinePlugin({ - 'process.env.ESM': true, - }), - ], - }), - ] - : [ - new InjectManifest({ - swSrc: swPath, - include: [ - /200\.html$/, - /\.js$/, - /\.css$/, - /\.(png|jpg|svg|gif|webp)$/, - ], - exclude: [/\.esm\.js$/], - }), - ]; + + if (env.esm) { + swInjectManifest.push( + new InjectManifest({ + swSrc: swPath, + swDest: 'sw-esm.js', + include: [ + /200\.html$/, + /\.esm.js$/, + /\.css$/, + /\.(png|jpg|svg|gif|webp)$/, + ], + webpackCompilationPlugins: [ + new webpack.DefinePlugin({ + 'process.env.ESM': true, + }), + ], + }) + ); + } + + swInjectManifest.push( + new InjectManifest({ + swSrc: swPath, + include: [/200\.html$/, /\.js$/, /\.css$/, /\.(png|jpg|svg|gif|webp)$/], + exclude: [/\.esm\.js$/], + }) + ); } let copyPatterns = [