refactor(@angular-devkit/build-optimizer): improve transitional Webpack 5 compatibility

This change provides both Webpack 4 and 5 compatible types for the the build optimizer Webpack plugin.
This commit is contained in:
Charles Lyding 2021-02-16 10:38:57 -05:00 committed by Alan Agius
parent a937012db2
commit d720d3db73
4 changed files with 22 additions and 4 deletions

View File

@ -3,7 +3,7 @@ export declare function buildOptimizer(options: BuildOptimizerOptions): Transfor
export declare const buildOptimizerLoaderPath: string;
export declare class BuildOptimizerWebpackPlugin {
apply(compiler: Compiler): void;
apply(compiler: Compiler | WebpackFourCompiler): void;
}
export default function buildOptimizerLoader(this: {

View File

@ -22,5 +22,9 @@
"webpack": {
"optional": true
}
},
"devDependencies": {
"@types/webpack": "^4.41.22",
"webpack": "5.21.2"
}
}

View File

@ -5,15 +5,15 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Compiler } from 'webpack';
import { Compiler, WebpackFourCompiler } from 'webpack';
interface ModuleData {
resourceResolveData: { descriptionFileData?: { typings?: string } };
}
export class BuildOptimizerWebpackPlugin {
apply(compiler: Compiler) {
compiler.hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
apply(compiler: Compiler | WebpackFourCompiler) {
(compiler as Compiler).hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
// tslint:disable-next-line: no-any
nmf.hooks.module.tap('BuildOptimizerWebpackPlugin', (module, data) => {
const { descriptionFileData } = (data as ModuleData).resourceResolveData;

View File

@ -0,0 +1,14 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as webpack from 'webpack';
import { Compiler as webpack4Compiler } from '@types/webpack';
// Webpack 5 transition support types
declare module 'webpack' {
export type WebpackFourCompiler = webpack4Compiler;
}