Skip to content

Commit dcf6a21

Browse files
Merge branch 'master' into legacy-bundles-regenerator
2 parents 10e234e + 9039ba2 commit dcf6a21

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
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

.changeset/sixty-badgers-dance.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+
Corrects error when `src/sw.js` does not exist and esm is disabled

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: join(src, 'sw.js'),
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 = [

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"stack-trace": "0.0.10",
128128
"style-loader": "^2.0.0",
129129
"terser-webpack-plugin": "^4.2.3",
130-
"typescript": "^4.2.4",
130+
"typescript": "~4.2.4",
131131
"update-notifier": "^5.1.0",
132132
"url-loader": "^4.1.1",
133133
"validate-npm-package-name": "^3.0.0",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14431,7 +14431,7 @@ typedarray@^0.0.6:
1443114431
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1443214432
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1443314433

14434-
typescript@^4.2.4:
14434+
typescript@~4.2.4:
1443514435
version "4.2.4"
1443614436
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
1443714437
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==

0 commit comments

Comments
 (0)