Besides ~@angular/material/theming, was mat-core() also imported accidentally? According to Angular Material document:
This should only be included once in your application. If this mixin is included multiple times, your application will end up with multiple copies of these common styles.
For my case, I just wanted to access the $primary and $accent colors in my own css files. Here's what I did:
Create a _variables.scss, that can be imported anywhere throughout the app
@import "~@angular/material/theming"; $primaryPalette: mat-palette($mat-pink, 700); $accentPalette: mat-palette($mat-blue-grey, A200, A100, A400); $warnPalette: mat-palette($mat-red); $theme: mat-dark-theme($primaryPalette, $accentPalette, $warnPalette); $primary: map-get($theme, primary); $accent: map-get($theme,accent); $background: map-get($theme, background); $foreground: map-get($theme, foreground);
Create a theme.scss, and add it into angular.json's styles array
@import "~@angular/material/theming"; @import "_variables"; @include mat-core(); @include angular-material-theme($theme);
And then everything works, without inflating the compiled css.
5mb(or whatever you need)