@@ -341,10 +341,26 @@ export function initializeInstance(
341341 instance . transformers = getCustomTransformers ( program ) ;
342342 // Setup watch run for solution building
343343 if ( instance . solutionBuilderHost ) {
344- loader . _compiler . hooks . afterCompile . tapAsync (
345- 'ts-loader' ,
346- makeAfterCompile ( instance , instance . configFilePath )
347- ) ;
344+ if ( loader . _compilation . hooks . afterProcessAssets ) {
345+ // afterProcessAssets does not exist in webpack4
346+ loader . _compilation . hooks . afterProcessAssets . tap (
347+ 'ts-loader' ,
348+ ( _ : any ) => {
349+ makeAfterCompile ( instance , instance . configFilePath ) (
350+ loader . _compilation ,
351+ ( ) => {
352+ return null ;
353+ }
354+ ) ;
355+ }
356+ ) ;
357+ } else {
358+ // adding assets in afterCompile is deprecated in webpack 5
359+ loader . _compiler . hooks . afterCompile . tapAsync (
360+ 'ts-loader' ,
361+ makeAfterCompile ( instance , instance . configFilePath )
362+ ) ;
363+ }
348364 loader . _compiler . hooks . watchRun . tapAsync (
349365 'ts-loader' ,
350366 makeWatchRun ( instance , loader )
@@ -391,11 +407,27 @@ export function initializeInstance(
391407 instance . languageService ! . getProgram ( )
392408 ) ;
393409 }
410+ if ( loader . _compilation . hooks . afterProcessAssets ) {
411+ // afterProcessAssets does not exist in webpack4
412+ loader . _compilation . hooks . afterProcessAssets . tap (
413+ 'ts-loader' ,
414+ ( _ : any ) => {
415+ makeAfterCompile ( instance , instance . configFilePath ) (
416+ loader . _compilation ,
417+ ( ) => {
418+ return null ;
419+ }
420+ ) ;
421+ }
422+ ) ;
423+ } else {
424+ // adding assets in afterCompile is deprecated in webpack 5
425+ loader . _compiler . hooks . afterCompile . tapAsync (
426+ 'ts-loader' ,
427+ makeAfterCompile ( instance , instance . configFilePath )
428+ ) ;
429+ }
394430
395- loader . _compiler . hooks . afterCompile . tapAsync (
396- 'ts-loader' ,
397- makeAfterCompile ( instance , instance . configFilePath )
398- ) ;
399431 loader . _compiler . hooks . watchRun . tapAsync (
400432 'ts-loader' ,
401433 makeWatchRun ( instance , loader )
0 commit comments