@@ -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+ / 2 0 0 \. h t m l $ / ,
56+ / \. e s m .j s $ / ,
57+ / \. c s s $ / ,
58+ / \. ( p n g | j p g | s v g | g i f | w e b p ) $ / ,
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+ / 2 0 0 \. h t m l $ / ,
72+ / \. j s $ / ,
73+ / \. c s s $ / ,
74+ / \. ( p n g | j p g | s v g | g i f | w e b p ) $ / ,
75+ ] ,
76+ exclude : [ / \. e s m \. j s $ / ] ,
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- / 2 0 0 \. h t m l $ / ,
128- / \. e s m .j s $ / ,
129- / \. c s s $ / ,
130- / \. ( p n g | j p g | s v g | g i f | w e b p ) $ / ,
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- / 2 0 0 \. h t m l $ / ,
144- / \. j s $ / ,
145- / \. c s s $ / ,
146- / \. ( p n g | j p g | s v g | g i f | w e b p ) $ / ,
147- ] ,
148- exclude : [ / \. e s m \. j s $ / ] ,
149- } ) ,
150- ]
151- : [ ] ) ,
150+ ...swInjectManifest ,
152151 ] ,
153152 } ;
154153}
0 commit comments