To enable CSS Preprocessor SASS/SCSS in Angular 6 project, we have update the config file (angular.json) or we can do it by Angular-CLI
By default, if we run
Scenario 1: ( Enabling SASS/SCSS in existing Angular project )
Using Angular-CLI
Manually
After enabling CSS Preprocessor, just do following steps
Scenario 2: ( Enabling SASS/SCSS in new Angular project )
Using Angular-CLI
Add
By default, if we run
ng new project-name
using terminal/cmd, the angular framework will be installed without enabling CSS Preprocessors in angular. To overcome this, follow the simple procedure shared belowScenario 1: ( Enabling SASS/SCSS in existing Angular project )
Using Angular-CLI
ng config schematics.@schematics/angular:component.styleext scss
Manually
- Open angular.json file
- Find "schematics": {}
- Add
"@schematics/angular:component": { "styleext": "scss" }
After enabling CSS Preprocessor, just do following steps
- Update all .css files to .scss (style.css in src folder and all custom generated components etc..)
- Open angular.json file
- Update all
"src/styles.css"
to"src/styles.scss"
Stop the server and restart.. All set to go with SCSS.
Scenario 2: ( Enabling SASS/SCSS in new Angular project )
Using Angular-CLI
Add
--style=sass
with the command to create new angular project
ng new project-name --style=sass