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 angular#28113
  • Loading branch information
alan-agius4 committed Jul 26, 2024
1 parent bd1e0d8 commit 9280c20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild';
import glob from 'fast-glob';
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';
import { extname, isAbsolute } from 'node:path';
import type { PostcssConfiguration } from '../../../utils/postcss-configuration';
import { LoadResultCache, createCachedLoad } from '../load-result-cache';

Expand Down Expand Up @@ -167,6 +167,12 @@ export class StylesheetPluginFactory {
build.onLoad(
{ filter: language.fileFilter },
createCachedLoad(cache, async (args) => {
if (!isAbsolute(args.path)) {
// The file being requested might be using the HTTP protocol.
// Example: `@import url(https://fonts.googleapis.com/earlyaccess/notokufiarabic.css);`
return null;
}

const data = await readFile(args.path, 'utf-8');

return processStylesheet(
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 9280c20

Please sign in to comment.