I wanted to re-use some structure from an Angular 5 project which uses Less. In this old project I could simply load .less
files using this line from within a component:
@import '~app/shared/less/bootstrap';
This would load:
/my-app/src/app/shared/less/bootstrap.less
Now I have a blank Angular 6 project, which is also configured to use Less as a preprocessor:
ng new my-app --routing --style less
Extract from angular.json
:
"my-app": {
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "less"
}
},
"architect": {
"build": {
"options": {
"styles": [
"src/styles.less",
"app/shared/less/styles.less"
However the line
@import '~app/shared/less/bootstrap';
… compiles with an error:
Failed to compile.
./src/app/shared/component/some.component.less
Module build failed:
@import '~app/shared/less/bootstrap';
^
'~app/shared/less/bootstrap' wasn't found.
I also tried:
@import '.app/shared/less/bootstrap';
@import '.src/app/shared/less/bootstrap';
@import '~app/shared/less/bootstrap.less';
… without any luck.
Did I forget to configue something?