Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions packages/angular_devkit/build_optimizer/package.json
Expand Up @@ -22,5 +22,9 @@
"webpack": {
"optional": true
}
},
"devDependencies": {
"@types/webpack": "^4.41.22",
"webpack": "5.21.2"
}
}
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions packages/angular_devkit/build_optimizer/src/webpack.d.ts
@@ -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;
}