For Angular 6 check the Official documentation
Note: For @angular/cli versions older than 6.0.0-beta.6 use ng set in place of ng config.
For existing projects
In an existing angular-cli project that was set up with the default css styles you will need to do a few things:
- Change the default style extension to
scss
Manually change in
.angular-cli.json(Angular 5.x and older) orangular.json(Angular 6+) or run:ng config defaults.styleExt=scss
if you get an error: Value cannot be found. use the command:
ng config schematics.@schematics/angular:component.styleext scss
(*source: Angular CLI SASS options)
Rename your existing
.cssfiles to.scss(i.e. styles.css and app/app.component.css)Point the CLI to find styles.scss
Manually change the file extensions in
apps[0].stylesinangular.json
- Point the components to find your new style files
Change the
styleUrlsin your components to match your new file names
For future projects
As @Serginho mentioned you can set the style extension when running the ng new command
ng new your-project-name --style=scss
If you want to set the default for all projects you create in the future run the following command:
ng config --global defaults.styleExt=scss
Answer from Chic on Stack OverflowFor Angular 6 check the Official documentation
Note: For @angular/cli versions older than 6.0.0-beta.6 use ng set in place of ng config.
For existing projects
In an existing angular-cli project that was set up with the default css styles you will need to do a few things:
- Change the default style extension to
scss
Manually change in
.angular-cli.json(Angular 5.x and older) orangular.json(Angular 6+) or run:ng config defaults.styleExt=scss
if you get an error: Value cannot be found. use the command:
ng config schematics.@schematics/angular:component.styleext scss
(*source: Angular CLI SASS options)
Rename your existing
.cssfiles to.scss(i.e. styles.css and app/app.component.css)Point the CLI to find styles.scss
Manually change the file extensions in
apps[0].stylesinangular.json
- Point the components to find your new style files
Change the
styleUrlsin your components to match your new file names
For future projects
As @Serginho mentioned you can set the style extension when running the ng new command
ng new your-project-name --style=scss
If you want to set the default for all projects you create in the future run the following command:
ng config --global defaults.styleExt=scss
As of ng6 this can be accomplished with the following code added to angular.json at the root level:
Manually change in .angular.json:
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
How do I use a CSS to SCSS converter?
Why would I want to use a CSS to SCSS converter?
What is a CSS to SCSS converter, and how does it work?
» npm install schematics-scss-migrate
In the latest version of Angular (v13), It's npm library migrating from css to scss and vice versa
ng add schematics-scss-migrate
If you created your project choosing the default style option as CSS, it's possible that neither.
ng config defaults.styleExt=scss nor
ng config schematics.@schematics/angular:component.style scss
work, since the Angular CLI will try to change these options in your angular.json file, and they are not created at all with the default CSS option. If none of these options work as a first step, you can add the entry in your angular.json file yourself, under schematics:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"myProject": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
...
This will of course only change the extension for the newly generated components. If you need to migrate your project, you would have to rename all your styles files changing the extension from CSS to SCSS, and also the reference to those files in the @Component directive of each component.