Skip to content

Commit

Permalink
Merge branch 'master' into legacy-bundles-regenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony authored Nov 22, 2021
2 parents 10e234e + 9039ba2 commit dcf6a21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-lions-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Fixing legacy SW generation while ESM is enabled
5 changes: 5 additions & 0 deletions .changeset/sixty-badgers-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Corrects error when `src/sw.js` does not exist and esm is disabled
58 changes: 28 additions & 30 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: join(src, 'sw.js'),
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 = [
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit dcf6a21

Please sign in to comment.