Skip to content

fix(@angular-devkit/build-angular): non injected styles should not count as initial #20787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ export function markAsyncChunksNonInitial(
.flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks);

// Find chunks for each ID.
const asyncChunks = asyncChunkIds
.map((chunkId) => {
const chunk = chunks.find((chunk) => chunk.id === chunkId);
if (!chunk) {
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
}
const asyncChunks = asyncChunkIds.map((chunkId) => {
const chunk = chunks.find((chunk) => chunk.id === chunkId);
if (!chunk) {
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
}

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

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

This file was deleted.

11 changes: 8 additions & 3 deletions tests/legacy-cli/e2e/tests/basic/styles-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';

export default async function() {
export default async function () {
await writeMultipleFiles({
'src/string-style.css': '.string-style { color: red }',
'src/input-style.css': '.input-style { color: red }',
Expand All @@ -12,7 +12,7 @@ export default async function() {
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }',
});

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

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

await expectFileToMatch('dist/test-project/styles.css', '.string-style');
await expectFileToMatch('dist/test-project/styles.css', '.input-style');
Expand All @@ -41,4 +41,9 @@ export default async function() {
<link rel="stylesheet" href="renamed-style.css">
`,
);

// Non injected styles should be listed under lazy chunk files
if (!/Lazy Chunk Files.*\srenamed-lazy-style\.css/m.test(stdout)) {
throw new Error(`Expected "renamed-lazy-style.css" to be listed under "Lazy Chunk Files".`);
}
}