Skip to content

styles that are not injected do count for initial bundle size. #17672

Closed
@roymilder

Description

@roymilder

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Unknown

Description

We generate different themes for our production build.
All are based on the same base styles with a different variables.scss.
We produce new files on each production build (which is handled by our ci/cd so build time is not that important).

the different styles are defined in the "styles" section of angular.json:

            "styles": [
              {
                "input": "./src/projects/contrast/styles.scss",
                "bundleName": "contrast",
                "inject": false
              },
              {
                "input": "./src/projects/projecta/styles.scss",
                "bundleName": "923a0aa8-73de-46f4-966a-26f1c39ce8e6",
                "inject": false
              },
              {
                "input": "./src/projects/projectb/styles.scss",
                "bundleName": "d945e725-7e1e-4fa5-b372-3d577b3d94cb",
                "inject": false
              },
and so on
              "src/styles.scss"
            ],
            "scripts": [
            ],

As you can see, the files are not injected.
In the production index.html I have verified that the files are not injected.

However, recently the budget exceeded for initial error caused our build to fail:

ERROR in budgets: Exceeded maximum budget for initial. Budget 5 MB was not met by 270 kB with a total of 5.26 MB.

When we removed the different themes, the error dissapeared.

When looking at the build log it looks like the size of all the additional themes are included sum of the initial bundle size and thus are the cause of exceeding the limit (but in fact they are not, which is 👍 )

Screenshot 2020-05-08 at 14 11 14

🔬 Minimal Reproduction

🔥 Exception or Error


ERROR in budgets: Exceeded maximum budget for initial. Budget 5 MB was not met by 270 kB with a total of 5.26 MB. 
The command '/bin/sh -c ng build --prod --source-map=false' returned a non-zero code: 1 

🌍 Your Environment


Angular CLI: 9.1.4
Node: 12.13.0
OS: darwin x64

Angular: 9.1.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.4
@angular-devkit/build-angular     0.901.4
@angular-devkit/build-optimizer   0.901.4
@angular-devkit/build-webpack     0.901.4
@angular-devkit/core              9.1.4
@angular-devkit/schematics        9.1.4
@angular/cdk                      9.2.2
@ngtools/webpack                  9.1.4
@schematics/angular               9.1.4
@schematics/update                0.901.4
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.42.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions