Skip to content

Commit 5325f97

Browse files
committed
fix(@angular-devkit/build-angular): prevent webpack from adding suffixes to polyfills files
The ES5 polyfills file was erroneously being suffixed with `es2015`. The webpack configuration does not support conditional customization per chunk for the output filenames (`chunkFilename` option schema only supports string values). This change adds an additional small webpack plugin that allows the chunk filenames to be adjusted based on the chunk name. The plugin is only added when differential loading is enabled as this is the only time that a chunk currently requires its filename to be adjusted. Closes angular#15915
1 parent 7e7248d commit 5325f97

File tree

1 file changed

+26
-5
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs

1 file changed

+26
-5
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import * as path from 'path';
1515
import { RollupOptions } from 'rollup';
1616
import { ScriptTarget } from 'typescript';
1717
import {
18+
ChunkData,
1819
Compiler,
1920
Configuration,
2021
ContextReplacementPlugin,
2122
HashedModuleIdsPlugin,
23+
Plugin,
2224
Rule,
2325
compilation,
2426
debug,
@@ -57,11 +59,13 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
5759
throw new Error('Cannot locate node_modules directory.');
5860
}
5961

60-
// tslint:disable-next-line:no-any
61-
const extraPlugins: any[] = [];
62+
const extraPlugins: Plugin[] = [];
6263
const extraRules: Rule[] = [];
6364
const entryPoints: { [key: string]: string[] } = {};
6465

66+
// determine hashing format
67+
const hashFormat = getOutputHashFormat(buildOptions.outputHashing || 'none');
68+
6569
const targetInFileName = getEsVersionForFileName(
6670
tsConfig.options.target,
6771
buildOptions.esVersionInFileName,
@@ -146,6 +150,26 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
146150
// Add zone.js legacy support to the es5 polyfills
147151
// This is a noop execution-wise if zone-evergreen is not used.
148152
entryPoints[polyfillsChunkName].push('zone.js/dist/zone-legacy');
153+
154+
// Since the chunkFileName option schema does not allow the function overload, add a plugin
155+
// that changes the name of the ES5 polyfills chunk to not include ES2015.
156+
extraPlugins.push({
157+
apply(compiler) {
158+
compiler.hooks.compilation.tap('build-angular', compilation => {
159+
// Webpack typings do not contain MainTemplate assetPath hook
160+
// The webpack.Compilation assetPath hook is a noop in 4.x
161+
// tslint:disable-next-line: no-any
162+
(compilation.mainTemplate.hooks as any).assetPath.tap(
163+
'build-angular',
164+
(filename: string, data: ChunkData) => {
165+
return data.chunk && data.chunk.name === 'polyfills-es5'
166+
? `polyfills-es5${hashFormat.chunk}.js`
167+
: filename;
168+
},
169+
);
170+
});
171+
},
172+
});
149173
}
150174
if (!buildOptions.aot) {
151175
if (differentialLoadingMode) {
@@ -183,9 +207,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
183207
);
184208
}
185209

186-
// determine hashing format
187-
const hashFormat = getOutputHashFormat(buildOptions.outputHashing || 'none');
188-
189210
// process global scripts
190211
const globalScriptsByBundleName = normalizeExtraEntryPoints(
191212
buildOptions.scripts,

0 commit comments

Comments
 (0)