Skip to content

Commit d720d3d

Browse files
clydinalan-agius4
authored andcommitted
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.
1 parent a937012 commit d720d3d

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

etc/api/angular_devkit/build_optimizer/src/_golden-api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export declare function buildOptimizer(options: BuildOptimizerOptions): Transfor
33
export declare const buildOptimizerLoaderPath: string;
44

55
export declare class BuildOptimizerWebpackPlugin {
6-
apply(compiler: Compiler): void;
6+
apply(compiler: Compiler | WebpackFourCompiler): void;
77
}
88

99
export default function buildOptimizerLoader(this: {

packages/angular_devkit/build_optimizer/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
"webpack": {
2323
"optional": true
2424
}
25+
},
26+
"devDependencies": {
27+
"@types/webpack": "^4.41.22",
28+
"webpack": "5.21.2"
2529
}
2630
}

packages/angular_devkit/build_optimizer/src/build-optimizer/webpack-plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Compiler } from 'webpack';
8+
import { Compiler, WebpackFourCompiler } from 'webpack';
99

1010
interface ModuleData {
1111
resourceResolveData: { descriptionFileData?: { typings?: string } };
1212
}
1313

1414
export class BuildOptimizerWebpackPlugin {
15-
apply(compiler: Compiler) {
16-
compiler.hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
15+
apply(compiler: Compiler | WebpackFourCompiler) {
16+
(compiler as Compiler).hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
1717
// tslint:disable-next-line: no-any
1818
nmf.hooks.module.tap('BuildOptimizerWebpackPlugin', (module, data) => {
1919
const { descriptionFileData } = (data as ModuleData).resourceResolveData;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import * as webpack from 'webpack';
9+
import { Compiler as webpack4Compiler } from '@types/webpack';
10+
11+
// Webpack 5 transition support types
12+
declare module 'webpack' {
13+
export type WebpackFourCompiler = webpack4Compiler;
14+
}

0 commit comments

Comments
 (0)