Skip to content

Commit 43231d9

Browse files
alan-agius4alexeagle
authored andcommitted
refactor: script webpack plugin remove webpack 3 code
1 parent 18ff08d commit 43231d9

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

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

+9-33
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,18 @@ interface ScriptOutput {
3737
}
3838

3939
function addDependencies(compilation: any, scripts: string[]): void {
40-
if (compilation.fileDependencies.add) {
41-
// Webpack 4+ uses a Set
42-
for (const script of scripts) {
43-
compilation.fileDependencies.add(script);
44-
}
45-
} else {
46-
// Webpack 3
47-
compilation.fileDependencies.push(...scripts);
40+
for (const script of scripts) {
41+
compilation.fileDependencies.add(script);
4842
}
4943
}
5044

5145
function hook(compiler: any, action: (compilation: any, callback: (err?: Error) => void) => void) {
52-
if (compiler.hooks) {
53-
// Webpack 4
54-
compiler.hooks.thisCompilation.tap('scripts-webpack-plugin', (compilation: any) => {
55-
compilation.hooks.additionalAssets.tapAsync(
56-
'scripts-webpack-plugin',
57-
(callback: (err?: Error) => void) => action(compilation, callback),
58-
);
59-
});
60-
} else {
61-
// Webpack 3
62-
compiler.plugin('this-compilation', (compilation: any) => {
63-
compilation.plugin(
64-
'additional-assets',
65-
(callback: (err?: Error) => void) => action(compilation, callback),
66-
);
67-
});
68-
}
46+
compiler.hooks.thisCompilation.tap('scripts-webpack-plugin', (compilation: any) => {
47+
compilation.hooks.additionalAssets.tapAsync(
48+
'scripts-webpack-plugin',
49+
(callback: (err?: Error) => void) => action(compilation, callback),
50+
);
51+
});
6952
}
7053

7154
export class ScriptsWebpackPlugin {
@@ -81,14 +64,7 @@ export class ScriptsWebpackPlugin {
8164
}
8265

8366
for (let i = 0; i < scripts.length; i++) {
84-
let scriptTime;
85-
if (compilation.fileTimestamps.get) {
86-
// Webpack 4+ uses a Map
87-
scriptTime = compilation.fileTimestamps.get(scripts[i]);
88-
} else {
89-
// Webpack 3
90-
scriptTime = compilation.fileTimestamps[scripts[i]];
91-
}
67+
const scriptTime = compilation.fileTimestamps.get(scripts[i]);
9268
if (!scriptTime || scriptTime > this._lastBuildTime) {
9369
this._lastBuildTime = Date.now();
9470
return false;

0 commit comments

Comments
 (0)