How to turn on sass-loader in Angular?
I try to use @import "theme.scss"; inside*.scss` files.
But I get message;
File to import not found or unreadable: theme.scss.
I dont use webpack, only tsconfig and angular.jon
Where file theme.scss contains variables:
$border-radius: 10px;
$main: rgb(20, 100, 192);
.scss file into other .scss filesYou can specify the .scss inside other .scss files using the relative path of your file inside the assets path.
Your default assets path should be
"assets": [
"src/favicon.ico",
"src/assets"
]
which is defined in the angular.json file.
Example:
app.component.scsstheme.scss file is in ./src/assets/theme/theme.scssThen you would import it inside app.component.scss like:
@import '../assets/theme/theme.scss';
If you want to shorten the path like you described, you just add the path to the stylePreprocessorOptions in the angular.json file:
"architect": {
"build": {
...
"options": {
...
"stylePreprocessorOptions": {
"includePaths": [
"./src/assets/style/theme"
]
},
},
"test": {
...
"options": {
...
"stylePreprocessorOptions": {
"includePaths": [
"./src/assets/style/theme"
]
}
}
}
}
Then you should be able to include your file like @import 'theme.scss';
I suppose you set the wrong relative path. Therefore you need to set the stylePreprocessorOptions like that:
"includePaths": ["./src/lib"]
in build and test
After you set this, you can put in any theme file there and like:
./src/lib/theme.scss and import it like @import 'theme.scss';
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