mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 02:24:10 +08:00
fix(@ngtools/webpack): remove Webpack 5 deprecation warning in resource loader
This change adds support for using the Webpack `processAssets` hook to handle the resource loader child compilation's assets. This new hook is the recommended way to process assets in Webpack 5+.
This commit is contained in:
parent
d5645675fd
commit
3504c43e48
@ -9,6 +9,7 @@ import * as vm from 'vm';
|
||||
import { Compiler, compilation } from 'webpack';
|
||||
import { RawSource } from 'webpack-sources';
|
||||
import { normalizePath } from './ivy/paths';
|
||||
import { isWebpackFiveOrHigher } from './webpack-version';
|
||||
|
||||
const NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
|
||||
const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
|
||||
@ -132,13 +133,25 @@ export class WebpackResourceLoader {
|
||||
|
||||
let finalContent: string | undefined;
|
||||
let finalMap: string | undefined;
|
||||
childCompiler.hooks.afterCompile.tap('angular-compiler', (childCompilation) => {
|
||||
finalContent = childCompilation.assets[filePath]?.source().toString();
|
||||
finalMap = childCompilation.assets[filePath + '.map']?.source().toString();
|
||||
if (isWebpackFiveOrHigher()) {
|
||||
childCompiler.hooks.compilation.tap('angular-compiler', (childCompilation) => {
|
||||
childCompilation.hooks.processAssets.tap('angular-compiler', () => {
|
||||
finalContent = childCompilation.assets[filePath]?.source().toString();
|
||||
finalMap = childCompilation.assets[filePath + '.map']?.source().toString();
|
||||
|
||||
delete childCompilation.assets[filePath];
|
||||
delete childCompilation.assets[filePath + '.map'];
|
||||
});
|
||||
delete childCompilation.assets[filePath];
|
||||
delete childCompilation.assets[filePath + '.map'];
|
||||
});
|
||||
});
|
||||
} else {
|
||||
childCompiler.hooks.afterCompile.tap('angular-compiler', (childCompilation) => {
|
||||
finalContent = childCompilation.assets[filePath]?.source().toString();
|
||||
finalMap = childCompilation.assets[filePath + '.map']?.source().toString();
|
||||
|
||||
delete childCompilation.assets[filePath];
|
||||
delete childCompilation.assets[filePath + '.map'];
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise<CompilationOutput>((resolve, reject) => {
|
||||
childCompiler.runAsChild((error, _, childCompilation) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user