I know it's possible to use both css and sass/scss in the same project. I've looked at a SO question where this was asked, but from what I saw there was a lot of warnings popping up when using css as styleExt in the angular_cli.json file.
With the help of Angular CLI, you can install CSS or SCSS on your project and start working on that in a suitable way. If you are working with the CSS or SCSS in your angular project then it is very easy for you as compared to most other frameworks.
css codes. Every . css code can be included in . scss files.
We can easily import CSS files in the sass file. But it is forbidden not to include the . css extension in the import statement.
SCSS contains all the features of CSS and contains more features that are not present in CSS which makes it a good choice for developers to use it. SCSS is full of advanced features. SCSS offers variables, you can shorten your code by using variables. It is a great advantage over conventional CSS.
If you see angular-cli.json, "styles":
is an array. So it should allow us to add multiple style files as a comma-separated array. That should remove the warnings.
However, I think it is better to have similar styles across your application. If you want to convert all your files to scss/sass, you can do so in the following way:
my-file.css
to my-file.scss
..component.ts
file, update the styleUrls
with .scss/.sass
filename. Eg: styleUrls: ['my-file.css']
to styleUrls: ['my-file.scss']
styles:[ "styles.css"],
in angular-cli.json
to styles:["styles.scss],
, and that should do it!You can learn more about sass/scss here: Sass Lang Guide
Rename your files from sass to scss. Scss is recognized worldwide, sass is simply a syntax of another language derived from css. The compilers recognize scss.
Use this command to change your project extensions
ng set defaults.styleExt=scss
Manually change .angular.json
:
"styleExt": "scss"
You can also change extensions manually, nothing happens.
1. In local style case, it is not recommendable. Becasue it is too complex to handle both type for every components in angular. But for global style , defer load CSS or inline css, you can choose that as option.
For 2. 3. Use .scss if you already have some .css codes. Every .css code can be included in .scss files. For more details, please read this link.
4. There are good descriptions in Sourangshu's answer and https://angular.io/guide/component-styles#component-styles and the link in 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With