Skip to content
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

refactor(@angular/build): support external runtime component stylesheets in application builder #28330

Merged

Conversation

clydin
Copy link
Member

@clydin clydin commented Aug 30, 2024

To support automatic component style HMR, application builder in development mode now provides support for generating external runtime component stylesheets. This capability leverages the upcoming support within the AOT -compiler to emit components that generate link elements instead of embedding the stylesheet contents for file-based styles (e.g., styleUrl). In combination with support within the development server to handle requests for component stylesheets, file-based component stylesheets will be able to be replaced without a full page reload.

The implementation leverages the AOT compiler option externalRuntimeStyles which uses the result of the resource handler's resolution and emits new external stylesheet metadata within the component output code. This new metadata works in concert with the Angular runtime to generate link elements which can then leverage existing global stylesheet HMR capabilities.

This capability is current disabled by default while all elements are integrated across the CLI and framework and can be controlled via the NG_HMR_CSTYLES=1 environment variable. Once fully integrated the environment variable will unneeded.

This feature is only intended for use with the development server. Component styles within built code including production are not affected by this feature.

NOTE: Rebuild times have not yet been optimized. Future improvements will reduce the component stylesheet only rebuild time case.

@clydin clydin force-pushed the application/compile-external-component-styles branch from 8135c60 to fe044a0 Compare September 10, 2024 16:18
@clydin clydin removed the state: WIP label Sep 13, 2024
@clydin clydin marked this pull request as ready for review September 13, 2024 15:50
@clydin clydin added the target: major This PR is targeted for the next major release label Sep 18, 2024
@clydin clydin force-pushed the application/compile-external-component-styles branch from fe044a0 to 00acbf9 Compare September 19, 2024 20:19
…ets in application builder

To support automatic component style HMR, `application` builder in development mode now
provides support for generating external runtime component stylesheets. This capability
leverages the upcoming support within the AOT -compiler to emit components that generate
`link` elements instead of embedding the stylesheet contents for file-based styles
(e.g., `styleUrl`). In combination with support within the development server to handle
requests for component stylesheets, file-based component stylesheets will be able to be
replaced without a full page reload.

The implementation leverages the AOT compiler option `externalRuntimeStyles` which uses
the result of the resource handler's resolution and emits new external stylesheet metadata
within the component output code. This new metadata works in concert with the Angular runtime
to generate `link` elements which can then leverage existing global stylesheet HMR capabilities.

This capability is current disabled by default while all elements are integrated across the
CLI and framework and can be controlled via the `NG_HMR_CSTYLES=1` environment variable.
Once fully integrated the environment variable will unneeded.

This feature is only intended for use with the development server. Component styles within
in built code including production are not affected by this feature.

NOTE: Rebuild times have not yet been optimized. Future improvements will reduce the component
stylesheet only rebuild time case.
…component styles

The build system will now transform inline styles into a corresponding external runtime
style with a URL for the Angular AOT compiler when the development server has enabled
component HMR for styles. This allows both file-based and inline component styles to
be eligible for component style HMR. The inline styles are provided to the development
server in an equivalent form to the file-based styles which the Angular runtime will
request via `link` elements during development. A unique identifier is produced for
each inline style that combines the containing file and order of the style within the
containing file to represent the location of the style. This provides an equivalent
unique identifier to the full path used by file-based styles.
@clydin clydin force-pushed the application/compile-external-component-styles branch from 00acbf9 to ca176d4 Compare September 23, 2024 17:56
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 23, 2024
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 24, 2024
@clydin clydin merged commit 1548827 into angular:main Sep 24, 2024
32 checks passed
@clydin clydin deleted the application/compile-external-component-styles branch September 24, 2024 19:43
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/build target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants