@@ -164,23 +164,7 @@ export class SetPublicPathPlugin implements Webpack.Plugin {
164164 compiler . hooks . compilation . tap ( PLUGIN_NAME , ( compilation : Webpack . compilation . Compilation ) => {
165165 const v4MainTemplate : IV4MainTemplate = compilation . mainTemplate as IV4MainTemplate ;
166166 v4MainTemplate . hooks . startup . tap ( PLUGIN_NAME , ( source : string , chunk : IV4Chunk , hash : string ) => {
167- let assetOrChunkFound : boolean = ! ! this . options . skipDetection ;
168-
169- if ( ! assetOrChunkFound ) {
170- for ( const chunkGroup of chunk . groupsIterable ) {
171- const children : Webpack . compilation . Chunk [ ] = chunkGroup . getChildren ( ) ;
172- assetOrChunkFound = assetOrChunkFound || ( children . length > 0 ) ;
173- }
174- }
175-
176- if ( ! assetOrChunkFound ) {
177- for ( const innerModule of chunk . modulesIterable ) {
178- if ( innerModule . buildInfo . assets && Object . keys ( innerModule . buildInfo . assets ) . length > 0 ) {
179- assetOrChunkFound = true ;
180- }
181- }
182- }
183-
167+ const assetOrChunkFound : boolean = ! ! this . options . skipDetection || this . _detectAssetsOrChunks ( chunk ) ;
184168 if ( assetOrChunkFound ) {
185169 return this . _getStartupCode ( {
186170 source,
@@ -247,6 +231,23 @@ export class SetPublicPathPlugin implements Webpack.Plugin {
247231 }
248232 }
249233
234+ private _detectAssetsOrChunks ( chunk : IV4Chunk ) : boolean {
235+ for ( const chunkGroup of chunk . groupsIterable ) {
236+ const children : Webpack . compilation . Chunk [ ] = chunkGroup . getChildren ( ) ;
237+ if ( children . length > 0 ) {
238+ return true ;
239+ }
240+ }
241+
242+ for ( const innerModule of chunk . modulesIterable ) {
243+ if ( innerModule . buildInfo . assets && Object . keys ( innerModule . buildInfo . assets ) . length > 0 ) {
244+ return true ;
245+ }
246+ }
247+
248+ return false ;
249+ }
250+
250251 private _getStartupCode ( options : IStartupCodeOptions ) : string {
251252 const moduleOptions : IInternalOptions = cloneDeep ( this . options ) ;
252253
0 commit comments