Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding the Angular Material theme to Stackblitz Projects with Angular 17?

In previous versions of Stackblitz there used to be a styles.css file and to use one of the prebuilt themes we could just add an import to styles.css like this.

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

However with the latest Stackblitz which uses global_styles.css this errors.

https://stackblitz.com/edit/stackblitz-starters-od474b?file=src%2Fmain.ts,src%2Fglobal_styles.css

How do we import themes in Stackblitz with Angular 17?

like image 976
Ole Avatar asked Nov 19 '25 15:11

Ole


1 Answers

v17 uses the application builder when creating a project from scratch.

This builder relies on Esbuild which doesn't support "~" in path (it's a webpack feature).

Remove the ~ and you're good.

@import '@angular/material/prebuilt-themes/indigo-pink.css';

Also you're missing the MatButtonModule in your example and dont forget to import the icons font.

like image 99
Matthieu Riegler Avatar answered Nov 21 '25 07:11

Matthieu Riegler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!