Skip to content

Commit 4ac556b

Browse files
committed
fix(@angular-devkit/build-angular): non injected styles should not count as initial
Closes #20781 (cherry picked from commit 2643fb1)
1 parent a817592 commit 4ac556b

File tree

3 files changed

+15
-158
lines changed

3 files changed

+15
-158
lines changed

packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,14 @@ export function markAsyncChunksNonInitial(
3030
.flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks);
3131

3232
// Find chunks for each ID.
33-
const asyncChunks = asyncChunkIds
34-
.map((chunkId) => {
35-
const chunk = chunks.find((chunk) => chunk.id === chunkId);
36-
if (!chunk) {
37-
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
38-
}
33+
const asyncChunks = asyncChunkIds.map((chunkId) => {
34+
const chunk = chunks.find((chunk) => chunk.id === chunkId);
35+
if (!chunk) {
36+
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
37+
}
3938

40-
return chunk;
41-
})
42-
// All Webpack chunks are dependent on `runtime`, which is never an async
43-
// entry point, simply ignore this one.
44-
.filter((chunk) => !!chunk.names?.includes('runtime'));
39+
return chunk;
40+
});
4541

4642
// A chunk is considered `initial` only if Webpack already belives it to be initial
4743
// and the application developer did not mark it async via an extra entry point.

packages/angular_devkit/build_angular/src/webpack/utils/async-chunks_spec.ts

-144
This file was deleted.

tests/legacy-cli/e2e/tests/basic/styles-array.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
33
import { ng } from '../../utils/process';
44
import { updateJsonFile } from '../../utils/project';
55

6-
export default async function() {
6+
export default async function () {
77
await writeMultipleFiles({
88
'src/string-style.css': '.string-style { color: red }',
99
'src/input-style.css': '.input-style { color: red }',
@@ -12,7 +12,7 @@ export default async function() {
1212
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }',
1313
});
1414

15-
await updateJsonFile('angular.json', workspaceJson => {
15+
await updateJsonFile('angular.json', (workspaceJson) => {
1616
const appArchitect = workspaceJson.projects['test-project'].architect;
1717
appArchitect.build.options.styles = [
1818
{ input: 'src/string-style.css' },
@@ -27,7 +27,7 @@ export default async function() {
2727
];
2828
});
2929

30-
await ng('build', '--extract-css', '--configuration=development');
30+
const { stdout } = await ng('build', '--extract-css', '--configuration=development');
3131

3232
await expectFileToMatch('dist/test-project/styles.css', '.string-style');
3333
await expectFileToMatch('dist/test-project/styles.css', '.input-style');
@@ -41,4 +41,9 @@ export default async function() {
4141
<link rel="stylesheet" href="renamed-style.css">
4242
`,
4343
);
44+
45+
// Non injected styles should be listed under lazy chunk files
46+
if (!/Lazy Chunk Files.*\srenamed-lazy-style\.css/m.test(stdout)) {
47+
throw new Error(`Expected "renamed-lazy-style.css" to be listed under "Lazy Chunk Files".`);
48+
}
4449
}

0 commit comments

Comments
 (0)