Skip to content

Commit fdff16d

Browse files
committed
refactor: (Hopefully) improving readability
1 parent 341b3f6 commit fdff16d

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,45 @@ async function clientConfig(env) {
3737
polyfills: resolve(__dirname, './polyfills'),
3838
};
3939

40-
let swPath;
40+
let swInjectManifest = [];
4141
if (env.sw) {
42-
swPath = join(__dirname, '..', '..', '..', 'sw', 'sw.js');
42+
let swPath = join(__dirname, '..', '..', '..', 'sw', 'sw.js');
4343
const userSwPath = join(src, 'sw.js');
4444
if (existsSync(userSwPath)) {
4545
swPath = userSwPath;
4646
} else {
4747
warn(`Could not find sw.js in ${src}. Using the default service worker.`);
4848
}
49+
swInjectManifest = env.esm
50+
? (swInjectManifest = [
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+
];
4979
}
5080

5181
return {
@@ -117,38 +147,7 @@ async function clientConfig(env) {
117147
},
118148
].filter(Boolean)
119149
),
120-
...(env.sw
121-
? env.esm
122-
? [
123-
new InjectManifest({
124-
swSrc: swPath,
125-
swDest: 'sw-esm.js',
126-
include: [
127-
/200\.html$/,
128-
/\.esm.js$/,
129-
/\.css$/,
130-
/\.(png|jpg|svg|gif|webp)$/,
131-
],
132-
webpackCompilationPlugins: [
133-
new webpack.DefinePlugin({
134-
'process.env.ESM': true,
135-
}),
136-
],
137-
}),
138-
]
139-
: [
140-
new InjectManifest({
141-
swSrc: join(src, 'sw.js'),
142-
include: [
143-
/200\.html$/,
144-
/\.js$/,
145-
/\.css$/,
146-
/\.(png|jpg|svg|gif|webp)$/,
147-
],
148-
exclude: [/\.esm\.js$/],
149-
}),
150-
]
151-
: []),
150+
...swInjectManifest,
152151
],
153152
};
154153
}

0 commit comments

Comments
 (0)