Skip to content

Commit 1532e32

Browse files
alan-agius4clydin
authored andcommitted
refactor: clean up webpack 4 code
1 parent 871f9ee commit 1532e32

File tree

8 files changed

+14
-98
lines changed

8 files changed

+14
-98
lines changed

packages/angular_devkit/build_angular/src/utils/webpack-version.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
Compiler,
1818
Configuration,
1919
ContextReplacementPlugin,
20+
ProgressPlugin,
2021
RuleSetRule,
2122
debug,
22-
sources,
2323
} from 'webpack';
2424
import { AssetPatternClass } from '../../browser/schema';
2525
import { BuildBrowserFeatures, maxWorkers } from '../../utils';
@@ -226,7 +226,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
226226
}
227227

228228
if (buildOptions.progress) {
229-
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
230229
const spinner = new Spinner();
231230

232231
extraPlugins.push(new ProgressPlugin({

packages/angular_devkit/build_angular/src/webpack/plugins/remove-hash-plugin.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { Compiler } from 'webpack';
9-
import { isWebpackFiveOrHigher } from '../../utils/webpack-version';
109
import { HashFormat } from '../utils/helpers';
1110

12-
1311
export interface RemoveHashPluginOptions {
1412
chunkNames: string[];
1513
hashFormat: HashFormat;
@@ -35,14 +33,7 @@ export class RemoveHashPlugin {
3533
return path;
3634
};
3735

38-
if (isWebpackFiveOrHigher()) {
39-
compilation.hooks.assetPath.tap('remove-hash-plugin', assetPath);
40-
} else {
41-
const mainTemplate = compilation.mainTemplate as typeof compilation.mainTemplate & {
42-
hooks: typeof compilation['hooks'];
43-
};
44-
mainTemplate.hooks.assetPath.tap('remove-hash-plugin', assetPath);
45-
}
36+
compilation.hooks.assetPath.tap('remove-hash-plugin', assetPath);
4637
});
4738
}
4839
}

packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
import { interpolateName } from 'loader-utils';
1010
import * as path from 'path';
11-
import { Compilation, Compiler } from 'webpack';
11+
import { Chunk, Compilation, Compiler } from 'webpack';
1212
import { CachedSource, ConcatSource, OriginalSource, RawSource, Source } from 'webpack-sources';
1313

14-
const Chunk = require('webpack/lib/Chunk');
15-
const EntryPoint = require('webpack/lib/Entrypoint');
16-
14+
const Entrypoint = require('webpack/lib/Entrypoint');
1715
export interface ScriptsWebpackPluginOptions {
1816
name: string;
1917
sourceMap?: boolean;
@@ -76,7 +74,7 @@ export class ScriptsWebpackPlugin {
7674
chunk.ids = [chunk.id];
7775
chunk.files.add(filename);
7876

79-
const entrypoint = new EntryPoint(this.options.name);
77+
const entrypoint = new Entrypoint(this.options.name);
8078
entrypoint.pushChunk(chunk);
8179
chunk.addGroup(entrypoint);
8280
compilation.entrypoints.set(this.options.name, entrypoint);

packages/angular_devkit/build_webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"webpack": "5.32.0"
1717
},
1818
"peerDependencies": {
19-
"webpack": "^4.6.0 || ^5.30.0",
19+
"webpack": "^5.30.0",
2020
"webpack-dev-server": "^3.1.4"
2121
}
2222
}

packages/ngtools/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"peerDependencies": {
2828
"@angular/compiler-cli": "^12.0.0-next",
2929
"typescript": "~4.2.3",
30-
"webpack": "^4.0.0 || ^5.30.0"
30+
"webpack": "^5.30.0"
3131
},
3232
"devDependencies": {
3333
"@angular-devkit/core": "0.0.0",

packages/ngtools/webpack/src/ivy/plugin.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import { CompilerHost, CompilerOptions, readConfiguration } from '@angular/compi
99
import { NgtscProgram } from '@angular/compiler-cli/src/ngtsc/program';
1010
import { createHash } from 'crypto';
1111
import * as ts from 'typescript';
12-
import { Compilation, Compiler, Module, NormalModuleReplacementPlugin } from 'webpack';
12+
import { Compilation, Compiler, Module, NormalModuleReplacementPlugin, util } from 'webpack';
1313
import { NgccProcessor } from '../ngcc_processor';
1414
import { TypeScriptPathsPlugin } from '../paths-plugin';
1515
import { WebpackResourceLoader } from '../resource_loader';
1616
import { addError, addWarning } from '../webpack-diagnostics';
17-
import { isWebpackFiveOrHigher, mergeResolverMainFields } from '../webpack-version';
1817
import { SourceFileCache } from './cache';
1918
import { DiagnosticsReporter, createDiagnosticsReporter } from './diagnostics';
2019
import {
@@ -144,7 +143,9 @@ export class AngularWebpackPlugin {
144143
}
145144
resolveOptions.plugins.push(pathsPlugin);
146145

147-
return mergeResolverMainFields(resolveOptions, originalMainFields, ivyMainFields);
146+
// https://github.com/webpack/webpack/issues/11635#issuecomment-707016779
147+
return util.cleverMerge(resolveOptions, { mainFields: [...ivyMainFields, '...'] });
148+
148149
});
149150
});
150151

@@ -256,15 +257,9 @@ export class AngularWebpackPlugin {
256257
.filter((sourceFile) => !internalFiles?.has(sourceFile));
257258

258259
// Ensure all program files are considered part of the compilation and will be watched
259-
if (isWebpackFiveOrHigher()) {
260-
allProgramFiles.forEach((sourceFile) =>
261-
compilation.fileDependencies.add(sourceFile.fileName),
262-
);
263-
} else {
264-
allProgramFiles.forEach((sourceFile) =>
265-
compilation.compilationDependencies.add(sourceFile.fileName),
266-
);
267-
}
260+
allProgramFiles.forEach((sourceFile) =>
261+
compilation.fileDependencies.add(sourceFile.fileName),
262+
);
268263

269264
compilation.hooks.finishModules.tapPromise(PLUGIN_NAME, async (modules) => {
270265
// Rebuild any remaining AOT required modules

packages/ngtools/webpack/src/webpack-version.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)