File tree Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,9 @@ class PreloadPlugin {
3535 } )
3636
3737 const htmlChunks = options . include === 'allAssets'
38- // Handle all chunks.
38+ // Handle all chunks.
3939 ? extractedChunks
40- // Only handle chunks imported by this HtmlWebpackPlugin.
40+ // Only handle chunks imported by this HtmlWebpackPlugin.
4141 : extractedChunks . filter ( ( chunk ) => doesChunkBelongToHTML ( {
4242 chunk,
4343 compilation,
@@ -84,21 +84,17 @@ class PreloadPlugin {
8484 rel : options . rel
8585 }
8686
87- // If we're preloading this resource (as opposed to prefetching),
88- // then we need to set the 'as' attribute correctly.
89- if ( options . rel === 'preload' ) {
90- attributes . as = determineAsValue ( {
91- href,
92- file,
93- optionsAs : options . as
94- } )
95-
96- // On the off chance that we have a cross-origin 'href' attribute,
97- // set crossOrigin on the <link> to trigger CORS mode. Non-CORS
98- // fonts can't be used.
99- if ( attributes . as === 'font' ) {
100- attributes . crossorigin = ''
101- }
87+ attributes . as = determineAsValue ( {
88+ href,
89+ file,
90+ optionsAs : options . as
91+ } )
92+
93+ // On the off chance that we have a cross-origin 'href' attribute,
94+ // set crossOrigin on the <link> to trigger CORS mode. Non-CORS
95+ // fonts can't be used.
96+ if ( options . rel === 'preload' && attributes . as === 'font' ) {
97+ attributes . crossorigin = ''
10298 }
10399
104100 links . push ( {
Original file line number Diff line number Diff line change @@ -400,10 +400,10 @@ module.exports = ({
400400 const links = dom . window . document . head . querySelectorAll ( 'link' )
401401 expect ( links . length ) . toBe ( 2 )
402402 expect ( links [ 0 ] . getAttribute ( 'rel' ) ) . toBe ( 'prefetch' )
403- expect ( links [ 0 ] . hasAttribute ( 'as' ) ) . toBeFalsy ( )
403+ expect ( links [ 0 ] . getAttribute ( 'as' ) ) . toBe ( 'script' )
404404 expect ( links [ 0 ] . getAttribute ( 'href' ) ) . toBe ( 'home.js' )
405405 expect ( links [ 1 ] . getAttribute ( 'rel' ) ) . toBe ( 'prefetch' )
406- expect ( links [ 1 ] . hasAttribute ( 'as' ) ) . toBeFalsy ( )
406+ expect ( links [ 1 ] . getAttribute ( 'as' ) ) . toBe ( 'script' )
407407 expect ( links [ 1 ] . getAttribute ( 'href' ) ) . toBe ( 'main.js' )
408408
409409 done ( )
You can’t perform that action at this time.
0 commit comments