Skip to content

Commit 0b4a86d

Browse files
Replace afterCompile to stop webpack 5 warning (#1200)
* Replace afterCompile to stop webpack 5 warning * Update src/instances.ts * Update src/instances.ts * Updated Changelog and bump version Co-authored-by: John Reilly <[email protected]>
1 parent 6d8d601 commit 0b4a86d

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v8.0.6
4+
* [Fixed further deprecation warning on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1196) - thanks @appzuka
5+
36
## v8.0.5
47
* [Fixed deprecation warnings on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1194) - thanks @sanex3339
58

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.5",
3+
"version": "8.0.6",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/instances.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)