Skip to content

Commit 9039ba2

Browse files
Fix/non esm sw generation (#1619)
* fix: Correcting non-esm sw generation * docs: Adding changeset * fix: Bad merge Co-authored-by: Leah <github.leah@hrmny.sh>
1 parent 11d5f3b commit 9039ba2

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

.changeset/seven-lions-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': patch
3+
---
4+
5+
Fixing legacy SW generation while ESM is enabled

packages/cli/lib/lib/webpack/webpack-client-config.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,34 @@ async function clientConfig(env) {
4646
} else {
4747
warn(`Could not find sw.js in ${src}. Using the default service worker.`);
4848
}
49-
swInjectManifest = env.esm
50-
? [
51-
new InjectManifest({
52-
swSrc: swPath,
53-
swDest: 'sw-esm.js',
54-
include: [
55-
/200\.html$/,
56-
/\.esm.js$/,
57-
/\.css$/,
58-
/\.(png|jpg|svg|gif|webp)$/,
59-
],
60-
webpackCompilationPlugins: [
61-
new webpack.DefinePlugin({
62-
'process.env.ESM': true,
63-
}),
64-
],
65-
}),
66-
]
67-
: [
68-
new InjectManifest({
69-
swSrc: swPath,
70-
include: [
71-
/200\.html$/,
72-
/\.js$/,
73-
/\.css$/,
74-
/\.(png|jpg|svg|gif|webp)$/,
75-
],
76-
exclude: [/\.esm\.js$/],
77-
}),
78-
];
49+
50+
if (env.esm) {
51+
swInjectManifest.push(
52+
new InjectManifest({
53+
swSrc: swPath,
54+
swDest: 'sw-esm.js',
55+
include: [
56+
/200\.html$/,
57+
/\.esm.js$/,
58+
/\.css$/,
59+
/\.(png|jpg|svg|gif|webp)$/,
60+
],
61+
webpackCompilationPlugins: [
62+
new webpack.DefinePlugin({
63+
'process.env.ESM': true,
64+
}),
65+
],
66+
})
67+
);
68+
}
69+
70+
swInjectManifest.push(
71+
new InjectManifest({
72+
swSrc: swPath,
73+
include: [/200\.html$/, /\.js$/, /\.css$/, /\.(png|jpg|svg|gif|webp)$/],
74+
exclude: [/\.esm\.js$/],
75+
})
76+
);
7977
}
8078

8179
let copyPatterns = [

0 commit comments

Comments
 (0)