question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to lazy load global style?

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0 node: 6.9.2 os: win32 x64 @angular/animations: 4.0.1 @angular/common: 4.0.1 @angular/compiler: 4.0.1 @angular/core: 4.0.1 @angular/forms: 4.0.1 @angular/http: 4.0.1 @angular/platform-browser: 4.0.1 @angular/platform-browser-dynamic: 4.0.1 @angular/router: 4.0.1 @angular/upgrade: 4.0.1 @angular/cli: 1.0.0 @angular/compiler-cli: 4.0.1

Repro steps.

  1. Read the following: https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/global-styles.md
  2. In my .angular-cli.json file, add the following to the styles array: “styles”: [ “scss/style.scss”, { “input”: “scss/style.client-1.scss”, “lazy”: true }, { “input”: “scss/style.client-2.scss”, “lazy”: true } ],
  3. What is next step to load either of these styles at runtime?

Desired functionality.

I need to provide different global styles for certain customers to my website and once they login, override certain bootstrap variables (colors, logo, etc). I have defined some client specific SCSS files and marked them as lazy load in the styles array.

Now I need to load them…help!

Docs in the link below mention “You can also rename the output and lazy load it by using the object format” - so how do I load them?

Mention any other details that might be useful.

https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/global-styles.md

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
aaronfrostcommented, Jun 13, 2018

I don’t know why this was closed. The question still very much remains.

When I lazy load a css file, the production build process output includes a chuck hash that I can’t know, making it impossible to know in my code the name of the file. Let me show. If I add the following to my angular-cli.json:

    "styles" : [
        { "input" : "foo.css", "lazy" : true }
    ]

then the build will output a file called foo.<some random hash>.bundle.js.

Because the file name is generated and not static, I can’t lazy load it. How do I get either the name to be static… or what is the prescribed way to do this by the Angular CLI team? I have the ability to create the lazy css file. How do I use it?

@filipesilva ^^^

5reactions
sumitaroracommented, Apr 27, 2017

Closing as above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular 4 multiple global styles with lazy loading
I am building an angular 4 application with angular-cli version 1.3.2 so far so good. I read in documentation that we can use...
Read more >
Angular — Lazy Load Common Styles Specific to a Feature ...
With ViewEncapuslation set to None, these styles will be available globally once the module is lazy loaded. This will happen whether you follow ......
Read more >
Angular Lazy Load Common Styles Specific to a Feature Module
With ViewEncapuslation set to None, these styles will be available globally once the module is lazy loaded and it might conflict with the...
Read more >
Lazy Load CSS at runtime with the Angular CLI - Egghead.io
[06:29] The problem here is that during development, if you go to that network panel and we refresh, you will see we get...
Read more >
Dynamically Load CSS with the Angular CLI | juri.dev
I've written about lazy loading in the past, as well as how to handle various styling issues in Angular. This time we'll explore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found