angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.79k stars 11.98k forks source link

Duplicate global styles in production build #20852

Closed JohnKis closed 3 years ago

JohnKis commented 3 years ago

🐞 Bug report

Command (mark with an x)

Is this a regression?

Yes, the previous version in which this bug was not present was: 11.2.10 ### Description Production builds on @angular/cli@12.0.0 generate duplicate global styles in index.html. In addition to this the `` tag loading the stylesheet has an inline event handler which forces users to weaken the app's CSP. ## πŸ”¬ Minimal Reproduction ``` ng new angular12-test cd angular12-test # Create at least one rule in style.css echo "html { position: relative; }" >> src/styles.css ng build --configuration production ``` This generates the following index.html file in the dist folder: ```html Angular12Test ``` Observe the the stylesheet is included: - inlined - as a link for `media="print"` with an inline event handler - in a `
alan-agius4 commented 3 years ago

Hi @JohnKis,

This is the expected default behaviour since version 12 and is due to critical css inlining and helps reduce. In version 11, this was opt-in behaviour.

You can read more about this;

You can opt-out of this feature at any time see: https://angular.io/guide/workspace-config#optimization-configuration

alan-agius4 commented 3 years ago

See also: https://github.com/angular/angular-cli/issues/20864

JohnKis commented 3 years ago

Thank you @alan-agius4. I'll apply the configuration change

angular-automatic-lock-bot[bot] commented 3 years ago

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.