File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,20 @@ class NetlifyServerPushPlugin {
2525 let mainJs = '# no js files' ;
2626 let mainCss = '# no css files' ;
2727
28+ const hasEsm = Object . keys ( compilation . assets ) . filter ( filename => / \. e s m \. j s $ / . test ( filename ) ) . length !== 0 ;
29+
2830 for ( const filename in compilation . assets ) {
2931 if ( ! / \. m a p $ / . test ( filename ) ) {
3032 if ( / r o u t e - / . test ( filename ) ) {
3133 routes . push ( filename ) ;
32- } else if ( / ^ s t y l e ( .+ ) \. c s s $ / . test ( filename ) ) {
34+ } else if ( / ^ ( s t y l e | b u n d l e ) ( .+ ) \. c s s $ / . test ( filename ) ) {
3335 mainCss = `Link: </${ filename } >; rel=preload; as=style` ;
34- } else if ( / ^ b u n d l e ( .+ ) \. j s $ / . test ( filename ) ) {
36+ } else if ( hasEsm && / ^ b u n d l e ( .+ ) \. e s m \. j s $ / . test ( filename ) ) {
37+ mainJs = `Link: </${ filename } >; rel=preload; as=script; crossorigin=anonymous` ;
38+ } else if ( ! hasEsm && / ^ b u n d l e ( .+ ) \. j s $ / . test ( filename ) ) {
3539 mainJs = `Link: </${ filename } >; rel=preload; as=script` ;
3640 }
37- }
41+ }
3842 }
3943
4044 let headers =
@@ -46,6 +50,10 @@ class NetlifyServerPushPlugin {
4650
4751 const redirects = `${ this . redirects . join ( '\n' ) } \n/* /index.html 200` ;
4852
53+ if ( ! routes . length ) {
54+ headers += `\n/*\n\t${ mainCss } \n\t${ mainJs } ` ;
55+ }
56+
4957 routes . forEach ( filename => {
5058 const path = filename
5159 . replace ( / r o u t e - / , '/' )
You can’t perform that action at this time.
0 commit comments