@@ -341,10 +341,26 @@ export function initializeInstance(
341
341
instance . transformers = getCustomTransformers ( program ) ;
342
342
// Setup watch run for solution building
343
343
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
+ }
348
364
loader . _compiler . hooks . watchRun . tapAsync (
349
365
'ts-loader' ,
350
366
makeWatchRun ( instance , loader )
@@ -391,11 +407,27 @@ export function initializeInstance(
391
407
instance . languageService ! . getProgram ( )
392
408
) ;
393
409
}
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
+ }
394
430
395
- loader . _compiler . hooks . afterCompile . tapAsync (
396
- 'ts-loader' ,
397
- makeAfterCompile ( instance , instance . configFilePath )
398
- ) ;
399
431
loader . _compiler . hooks . watchRun . tapAsync (
400
432
'ts-loader' ,
401
433
makeWatchRun ( instance , loader )
0 commit comments