Skip to content

Once I have created a lazy loaded css file, how do I lazy load it? #11235

@aaronfrost

Description

@aaronfrost

Among the many awesome things in the Angular CLI is the ability to lazy load a CSS file. My problem is that the documentation doesn't specify how to load it once you create it. When you run the build, the file that gets created for your css has a hash in the name, like foo.asdf908a7sd0as7g.bundle.css. Because the name of the production file isn't a static name, I can't figure out how to lazy load it. If there is a known way to do this, please show me, and I will help out and PR the docs.

Bug Report or Feature Request (mark with an x)

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

Area

- [ maybe ] devkit
- [ ] schematics
- [ X ] documentation

Versions

Angular CLI: 1.7.4
Node: 9.5.0
OS: darwin x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.2.5
@angular/cli: 1.7.4
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.4.9
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.6.2
webpack: 3.11.0

Repro steps

  1. Create a css file called foo.css.
  2. Edit the '.angular-cli.json` (I know in v6 it is called something else) to include the following in styles:
"styles":[
   ...
   {"input": "foo.css", "lazy": true}
]

The log given by the failure

There is no log, cause there is no failure.

Desired functionality

I would love to see a way to lazily load these css files.

Mention any other details that might be useful

#5880 was a similar question that never got answered and was closed. A few people suggested some work arounds that don't work for production mode when the css file gets the hash included in it's name. The suggestions only work in dev mode.

In a separate issue @filipesilva acknowledges that while a way to create lazily loaded css files exists, there is no provided way to load these created files. We need to get a way to allow people to load these created css files. In that issue, the participants are using native webpack functionality to load these css files. I don't want to use Webpack directly, because that will make it harder for me to upgrade my CLI one day when it switches to Bazel.

Activity

mansour-ahmed

mansour-ahmed commented on Jun 21, 2018

@mansour-ahmed

Having the same issue, an example will be helpful!

added a commit that references this issue on Jul 7, 2018
46b292d
filipesilva

filipesilva commented on Jul 7, 2018

@filipesilva
Contributor

Heya I was looking into this today and think I have a solution in #11491.

added 2 commits that reference this issue on Jul 7, 2018
9467d15
72f53c2
added 2 commits that reference this issue on Jul 10, 2018
3529096
323f13d
angular-automatic-lock-bot

angular-automatic-lock-bot commented on Sep 8, 2019

@angular-automatic-lock-bot

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.

locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @aaronfrost@filipesilva@mansour-ahmed@clydin

      Issue actions

        Once I have created a lazy loaded css file, how do I lazy load it? · Issue #11235 · angular/angular-cli