Skip to content

Some services are not tree-shaken when unused #18944

Open
@ranma42

Description

@ranma42

Reproduction

The issue cannot be shown using StackBlitz, but the repository https://github.com/ranma42/treeshake-material can be used to reproduce it.

The steps to reproduce the issue are illustrated in the commit messages of the repository. Namely:

  1. Create a new application with ng new treeshake-material with default settings (no routing, CSS style); it builds a 137 KB main.js.
  2. Install @angular/material with default settings (indigo-pink theme, no typography styles, yes to browser animations); the main.js now is 207 KB.
  3. Import several material modules in AppModule (without using any component or service); the main.js now is 271 KB.

It looks like some code is not being removed by the tree-shaking even if it is not being used.

Expected Behavior

The size of the build output does not grow unless components or services are actually used.

Actual Behavior

The size of the build output grows 2x just by installing and importing Angular Material modules, even if they are not being used.

Environment

  • Angular: 9.1.0
  • CDK/Material: 9.2.0
  • Browser(s): -
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: manyArea label for issues related to many components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions