Skip to content

Commit f5ee8a0

Browse files
alan-agius4mgechev
authored andcommitted
fix(@angular-devkit/build-angular): don't generate vendor.js.map when vendor sourcemaps is disabled
This reduced the build time of an `ng new` application from `5920ms` to `4616ms` Closes #18060
1 parent 6e65ec8 commit f5ee8a0

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
2727
styles: stylesSourceMap,
2828
scripts: scriptsSourceMap,
2929
hidden: hiddenSourceMap,
30+
vendor: vendorSourceMap,
3031
} = buildOptions.sourceMap;
3132

3233
if (subresourceIntegrity) {
@@ -53,6 +54,8 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
5354
scriptsSourceMap,
5455
stylesSourceMap,
5556
wco.differentialLoadingMode ? true : hiddenSourceMap,
57+
false,
58+
vendorSourceMap,
5659
));
5760
}
5861

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export function getServerConfig(wco: WebpackConfigOptions): Configuration {
2222
} = wco.buildOptions;
2323

2424
const extraPlugins = [];
25-
const { scripts, styles, hidden } = sourceMap;
25+
const { scripts, styles, hidden, vendor } = sourceMap;
2626
if (scripts || styles) {
27-
extraPlugins.push(getSourceMapDevTool(scripts, styles, hidden));
27+
extraPlugins.push(getSourceMapDevTool(scripts, styles, hidden, false, vendor));
2828
}
2929

3030
const externals: Configuration['externals'] = [...externalDependencies];

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ export function getTestConfig(
4848
});
4949
}
5050

51-
if (sourceMap.scripts || sourceMap.styles) {
52-
extraPlugins.push(getSourceMapDevTool(
53-
sourceMap.scripts,
54-
sourceMap.styles,
55-
false,
56-
true,
57-
));
51+
if (sourceMap) {
52+
const { styles, scripts, vendor } = sourceMap;
53+
54+
if (styles || scripts) {
55+
extraPlugins.push(getSourceMapDevTool(
56+
scripts,
57+
styles,
58+
false,
59+
true,
60+
vendor,
61+
));
62+
}
5863
}
5964

6065
return {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function getSourceMapDevTool(
7373
stylesSourceMap: boolean | undefined,
7474
hiddenSourceMap = false,
7575
inlineSourceMap = false,
76+
vendorSourceMap = false,
7677
): SourceMapDevToolPlugin {
7778
const include = [];
7879
if (scriptsSourceMap) {
@@ -93,6 +94,7 @@ export function getSourceMapDevTool(
9394
sourceRoot: inlineSourceMap ? '' : 'webpack:///',
9495
moduleFilenameTemplate: '[resource-path]',
9596
append: hiddenSourceMap ? false : undefined,
97+
exclude: vendorSourceMap ? undefined : /vendor.*\.js/,
9698
});
9799
}
98100

packages/angular_devkit/build_angular/src/browser/specs/differential_loading_spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ describe('Browser Builder with differential loading', () => {
5050
'runtime-es5.js.map',
5151

5252
'vendor-es2015.js',
53-
'vendor-es2015.js.map',
5453
'vendor-es5.js',
55-
'vendor-es5.js.map',
5654

5755
'styles.css',
5856
'styles.css.map',
@@ -90,9 +88,7 @@ describe('Browser Builder with differential loading', () => {
9088
'runtime-es5.js.map',
9189

9290
'vendor-es2016.js',
93-
'vendor-es2016.js.map',
9491
'vendor-es5.js',
95-
'vendor-es5.js.map',
9692

9793
'styles.css',
9894
'styles.css.map',
@@ -130,9 +126,7 @@ describe('Browser Builder with differential loading', () => {
130126
'runtime-es5.js.map',
131127

132128
'vendor-esnext.js',
133-
'vendor-esnext.js.map',
134129
'vendor-es5.js',
135-
'vendor-es5.js.map',
136130

137131
'styles.css',
138132
'styles.css.map',
@@ -158,7 +152,6 @@ describe('Browser Builder with differential loading', () => {
158152
'runtime.js.map',
159153

160154
'vendor.js',
161-
'vendor.js.map',
162155

163156
'styles.css',
164157
'styles.css.map',

packages/angular_devkit/build_angular/src/browser/specs/vendor-source-map_spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Browser Builder external source map', () => {
3434
expect(hasTsSourcePaths).toBe(true, `vendor.js.map should have '.ts' extentions`);
3535
});
3636

37-
it('does not map sourcemaps from external library when disabled', async () => {
37+
it(`does not generate 'vendor.js.map' when vendor sourcemap is disabled`, async () => {
3838
const overrides = {
3939
sourceMap: {
4040
scripts: true,
@@ -44,8 +44,6 @@ describe('Browser Builder external source map', () => {
4444
};
4545

4646
const { files } = await browserBuild(architect, host, target, overrides);
47-
const sourcePaths: string[] = JSON.parse(await files['vendor.js.map']).sources;
48-
const hasTsSourcePaths = sourcePaths.some(p => path.extname(p) == '.ts');
49-
expect(hasTsSourcePaths).toBe(false, `vendor.js.map not should have '.ts' extentions`);
47+
expect(files['vendor.js.map']).toBeUndefined();
5048
});
5149
});

tests/legacy-cli/e2e/tests/build/sourcemap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export default async function () {
1515
await ng('build', '--output-hashing=bundles', '--source-map');
1616

1717
await ng('build', '--prod', '--output-hashing=none', '--source-map');
18-
await testForSourceMaps(6);
18+
await testForSourceMaps(5);
1919

2020
await ng('build', '--output-hashing=none', '--source-map');
21-
await testForSourceMaps(8);
21+
await testForSourceMaps(6);
2222
}
2323

2424
async function testForSourceMaps(expectedNumberOfFiles: number): Promise <void> {
@@ -29,7 +29,7 @@ async function testForSourceMaps(expectedNumberOfFiles: number): Promise <void>
2929

3030
let count = 0;
3131
for (const file of files) {
32-
if (!file.endsWith('.js')) {
32+
if (!file.endsWith('.js') || file.startsWith('vendor-')) {
3333
continue;
3434
}
3535

0 commit comments

Comments
 (0)