Setting Up a CSS Preprocessor in Angular CLI

November 29, 2017 1 min read Angular Angular CLI

Would you like to integrate your favorite CSS Preprocessor (Sass/SCSS, Less or Stylus) with Angular CLI?

Angular CLI supports the popular CSS Preprocessors built-in: Sass/SCSS, Less and Stylus. Respectively, these formats are supported: sass, scss, less and styl.

In this post, we’re going to use scss as an example.

Starting a New Project

In case your project hasn’t been generated yet, you can set one of the supported CSS preprocessors while generating the project:

ng new sample-project --style=scss

Updating an Existing Project

In case your project was generated, but you want to set a preprocessor - you can change the default:

ng set defaults.styleExt scss

From now on, as soon as generating a new component - Angular CLI will create the style file with an appropriate format.

All that we’ve left is to adjust all styles in the project to the new format (actual file format and styleUrls metadata).

Note: Don’t forget to adjust the main styles file in angular-cli.json as well.

That’s it for today.