Skip to content

Commit

Permalink
fix(@angular/build): prevent build failures with remote CSS imports w…
Browse files Browse the repository at this point in the history
…hen Tailwind is configured

This addresses a bug where `@import url()` statements with remote CSS files (ending in .css) caused build errors when Tailwind was present. The issue arised from incorrect handling of remote URLs by the stylesheet plugin, which treated them as local files. This fix ensures proper handling of remote CSS imports.

Closes #28113

(cherry picked from commit 7d52941)
  • Loading branch information
alan-agius4 committed Jul 29, 2024
1 parent a28615d commit 747a144
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function createStylesheetBundleOptions(
];

if (options.inlineFonts) {
plugins.push(createCssInlineFontsPlugin({ cache, cacheOptions: options.cacheOptions }));
plugins.unshift(createCssInlineFontsPlugin({ cache, cacheOptions: options.cacheOptions }));
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class StylesheetPluginFactory {

// Add a load callback to support files from disk
build.onLoad(
{ filter: language.fileFilter },
{ filter: language.fileFilter, namespace: 'file' },
createCachedLoad(cache, async (args) => {
const data = await readFile(args.path, 'utf-8');

Expand Down
9 changes: 8 additions & 1 deletion tests/legacy-cli/e2e/tests/build/styles/tailwind-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ export default async function () {
await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;');

// Add Tailwind directives to a global style
await writeFile('src/styles.css', '@tailwind base; @tailwind components;');
await writeFile(
'src/styles.css',
`
@import url(https://fonts.googleapis.com/css?family=Roboto:400);
@tailwind base;
@tailwind components;
`,
);

// Ensure installation warning is present
const { stderr } = await ng('build', '--configuration=development');
Expand Down

0 comments on commit 747a144

Please sign in to comment.