问题
In some CSS files I have import:
@import "../../../theme.scss"
@import "../../theme.scss"
@import "../../../../../../theme.scss"
@import "../theme.scss"
How to use relative path as absolute path everywhere for all cases:
@import "theme.scss"
My full angulr.json code is:
"reon-core": {
"projectType": "library",
"root": "projects/reon-core",
"sourceRoot": "projects/reon-core/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"stylePreprocessorOptions": {
"includePaths": ["./projects/reon-core/src/lib/tssource/"]
},
"tsConfig": "projects/reon-core/tsconfig.lib.json",
"project": "projects/reon-core/ng-package.json"
}
}
....It returns Data path "" should NOT have additional properties(stylePreprocessorOptions).
;
回答1:
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 'app-theme.scss';
- For more insights read this: https://github.com/angular/angular-cli/wiki/stories-global-styles
- Official documentation: https://angular.io/guide/workspace-config
Update after description changed
I suppose you set the wrong relative path. Your root folder should be reon-core
. Therefore you need to set the stylePreprocessorOptions
like that:
"includePaths": ["./src/lib/tssource/"]
in build
and test
After you set this, you can put in any theme file there and like:
./src/lib/tssource/theme.scss
and import it like @import 'theme.scss';
回答2:
You can make this by adding to your tsconfig.json {compilerOptions: {path: HERE!!} }
"paths": {
"core-js/es7/reflect": ["node_modules/core-js/proposals/reflect-metadata"],
"core-js/es6/*": ["node_modules/core-js/es/*"],
"@swagger/*": ["src/app/_swagger/*"],
"@swagger": ["src/app/_swagger/index.ts"],
"@directives/*": ["src/app/_directives/*"],
"@services/*": ["src/app/_services/*"],
"@models/*": ["src/app/_models/*"],
"@tables/*": ["src/app/tables/*"],
"@tables_services/*": ["src/app/tables/services/*"],
"@shared/*": ["src/app/shared/*"],
"@language/*": ["src/app/_language/*"],
"moment": [
"node_modules/moment/min/moment.min.js"
]
}
回答3:
Assuming your theme.scss
is located in src/styles/theme.scss
or src/assets/styles/theme.scss
.
Add this path to angular.json
shown below
"stylePreprocessorOptions": {
"includePaths": [
"src/styles",
"src/assests/styles"
]
}
Now you can import it directly using path @import 'theme.scss'
回答4:
"stylePreprocessorOptions": {
"includePaths": [
"src/assets/styles",
"src/assets/styles/theme.scss"
]
Edit for your path to style file from src/PATH/theme.scss
than after rebuild your project restart I mean you can use it in your style like this
@import "theme";
来源:https://stackoverflow.com/questions/59661754/how-to-short-path-to-file-in-angular