Skip to content

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Sep 17, 2025

Current Behavior

When Angular components reference assets in their stylesheets using url() (e.g., background-image: url('../assets/test-pattern.svg')), the Nx Angular Rspack plugin processes the CSS but fails to extract and copy the referenced asset files to the output directory. This results in:

  • CSS is processed and URLs may be rewritten to reference output paths (e.g., url('./media/test-pattern.svg'))
  • The actual asset files are never copied to the output directory
  • Browser shows 404 errors for missing asset files when the application runs
  • No media directory is created in the build output

Expected Behavior

With this fix, assets referenced in component stylesheets are now properly extracted and emitted to the output directory:

  • Asset files referenced in component stylesheets are extracted and copied to the output directory
  • CSS URLs are correctly rewritten to point to the copied assets
  • No 404 errors occur for asset files
  • A media directory is created in the output with the extracted assets
  • Both inline and external component styles properly handle asset extraction

Related Issue(s)

Fixes #32487

Changes Made

Core Fix

  • Modified the Angular Rspack plugin to properly collect and emit stylesheet assets during the compilation process
  • Added asset collection during both bundle file and inline style processing in setup-compilation.ts and setup-with-angular-compilation.ts
  • Implemented asset emission in the processAssets hook of the Angular Rspack plugin

Test Coverage

  • Added comprehensive example application (examples/angular-rspack/csr-css-assets) that demonstrates:
    • External component stylesheets with asset references
    • Inline component styles with asset references
    • Various asset types (SVG, images)
    • Proper asset extraction and URL rewriting

Technical Details

The fix addresses the gap between Angular's ComponentStylesheetBundler which correctly processes assets and generates outputFiles, and the Nx Angular Rspack plugin which now properly emits these files using compilation.emitAsset() during the build process.

@Coly010 Coly010 requested review from a team as code owners September 17, 2025 13:45
@Coly010 Coly010 self-assigned this Sep 17, 2025
Copy link

vercel bot commented Sep 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Sep 17, 2025 1:58pm
Copy link
Contributor

nx-cloud bot commented Sep 17, 2025

View your CI Pipeline Execution ↗ for commit 5fb692e

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 7m 32s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 2m 29s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 7s View ↗
nx documentation ✅ Succeeded 3m 4s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-17 14:09:30 UTC

@Coly010 Coly010 merged commit 36741d0 into master Sep 18, 2025
16 of 18 checks passed
@Coly010 Coly010 deleted the 32487-extract-assets-from-stylesheets branch September 18, 2025 10:19
FrozenPandaz pushed a commit that referenced this pull request Sep 18, 2025
#32487 (#32759)

## Current Behavior

When Angular components reference assets in their stylesheets using
`url()` (e.g., `background-image: url('../assets/test-pattern.svg')`),
the Nx Angular Rspack plugin processes the CSS but fails to extract and
copy the referenced asset files to the output directory. This results
in:

- CSS is processed and URLs may be rewritten to reference output paths
(e.g., `url('./media/test-pattern.svg')`)
- The actual asset files are never copied to the output directory
- Browser shows 404 errors for missing asset files when the application
runs
- No `media` directory is created in the build output

## Expected Behavior

With this fix, assets referenced in component stylesheets are now
properly extracted and emitted to the output directory:

- Asset files referenced in component stylesheets are extracted and
copied to the output directory
- CSS URLs are correctly rewritten to point to the copied assets
- No 404 errors occur for asset files
- A `media` directory is created in the output with the extracted assets
- Both inline and external component styles properly handle asset
extraction

## Related Issue(s)

Fixes #32487

## Changes Made

### Core Fix
- Modified the Angular Rspack plugin to properly collect and emit
stylesheet assets during the compilation process
- Added asset collection during both bundle file and inline style
processing in `setup-compilation.ts` and
`setup-with-angular-compilation.ts`
- Implemented asset emission in the `processAssets` hook of the Angular
Rspack plugin

### Test Coverage
- Added comprehensive example application
(`examples/angular-rspack/csr-css-assets`) that demonstrates:
  - External component stylesheets with asset references
  - Inline component styles with asset references
  - Various asset types (SVG, images)
  - Proper asset extraction and URL rewriting

### Technical Details
The fix addresses the gap between Angular's `ComponentStylesheetBundler`
which correctly processes assets and generates `outputFiles`, and the Nx
Angular Rspack plugin which now properly emits these files using
`compilation.emitAsset()` during the build process.

(cherry picked from commit 36741d0)
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants