Skip to content

Commit

Permalink
Fix/non esm sw generation (#1619)
Browse files Browse the repository at this point in the history
* fix: Correcting non-esm sw generation

* docs: Adding changeset

* fix: Bad merge

Co-authored-by: Leah <github.leah@hrmny.sh>
  • Loading branch information
rschristian and ForsakenHarmony authored Nov 21, 2021
1 parent 11d5f3b commit 9039ba2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 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
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: 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 = [
Expand Down

0 comments on commit 9039ba2

Please sign in to comment.