Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to @import CSS file in Angular?

I have a file that I need to use in another css file.

For that I have added this to angular.json file:

   "styles": ["src/assets/css/theme.scss"],

Then I try to use it in a css file:

@import "theme.scss";

Angular can not find this path.

like image 904
OPV Avatar asked Dec 22 '22 20:12

OPV


1 Answers

If you want to point to a css/scss file within a component, you can add a shortcut to your styles folder in your angular.json in the options node like so :

        "my-app": {
            "root": "...",
            "sourceRoot": "...src",
            "projectType": "application",
            "architect": {

                "build": {
                    [...]
                    "options": {
                        [...]
                        "stylePreprocessorOptions": {
                          "includePaths": [
                            "projects/my-app/src/styles" // path to your styles folder
                          ]
                        }
                    }
                    
                },

            }
        },

Then, whenever you use @import "...";, it will start from the css folder, so you can use @import "theme.scss";

like image 164
GreatHawkeye Avatar answered Dec 28 '22 09:12

GreatHawkeye