@@ -21,22 +21,22 @@ const doesChunkBelongToHTML = require('./lib/does-chunk-belong-to-html')
2121const extractChunks = require ( './lib/extract-chunks' )
2222
2323class PreloadPlugin {
24- constructor ( options ) {
24+ constructor ( options ) {
2525 this . options = Object . assign ( { } , defaultOptions , options )
2626 this . webpackMajorVersion = 4
2727 }
2828
29- generateLinks ( compilation , htmlPluginData ) {
29+ generateLinks ( compilation , htmlPluginData ) {
3030 const options = this . options
3131 const extractedChunks = extractChunks ( {
3232 compilation,
3333 optionsInclude : options . include
3434 } )
3535
3636 const htmlChunks = options . include === 'allAssets'
37- // Handle all chunks.
37+ // Handle all chunks.
3838 ? extractedChunks
39- // Only handle chunks imported by this HtmlWebpackPlugin.
39+ // Only handle chunks imported by this HtmlWebpackPlugin.
4040 : extractedChunks . filter ( ( chunk ) => doesChunkBelongToHTML ( {
4141 chunk,
4242 compilation,
@@ -83,21 +83,17 @@ class PreloadPlugin {
8383 rel : options . rel
8484 }
8585
86- // If we're preloading this resource (as opposed to prefetching),
87- // then we need to set the 'as' attribute correctly.
88- if ( options . rel === 'preload' ) {
89- attributes . as = determineAsValue ( {
90- href,
91- file,
92- optionsAs : options . as
93- } )
94-
95- // On the off chance that we have a cross-origin 'href' attribute,
96- // set crossOrigin on the <link> to trigger CORS mode. Non-CORS
97- // fonts can't be used.
98- if ( attributes . as === 'font' ) {
99- attributes . crossorigin = ''
100- }
86+ attributes . as = determineAsValue ( {
87+ href,
88+ file,
89+ optionsAs : options . as
90+ } )
91+
92+ // On the off chance that we have a cross-origin 'href' attribute,
93+ // set crossOrigin on the <link> to trigger CORS mode. Non-CORS
94+ // fonts can't be used.
95+ if ( options . rel === 'preload' && attributes . as === 'font' ) {
96+ attributes . crossorigin = ''
10197 }
10298
10399 links . push ( {
@@ -110,7 +106,7 @@ class PreloadPlugin {
110106 return htmlPluginData
111107 }
112108
113- apply ( compiler ) {
109+ apply ( compiler ) {
114110 // for webpack5+, we can get webpack version from `compiler.webpack`
115111 if ( compiler . webpack ) {
116112 this . webpackMajorVersion = compiler . webpack . version . split ( '.' ) [ 0 ]
0 commit comments