如何在Angular中缩短文件路径? [英] How to short path to file in Angular?
问题描述
在我导入的一些 CSS 文件中:
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"
我完整的 angulr.json 代码是:
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"
}
}
....它返回数据路径"不应该有额外的属性(stylePreprocessorOptions).
;
推荐答案
只需在angular.json
文件中添加stylePreprocessorOptions
的路径即可:
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"
]
}
}
}
}
然后你应该能够像 @import 'app-theme.scss';
- 有关更多见解,请阅读:https://github.com/angular/angular-cli/wiki/stories-global-styles
- 官方文档:https://angular.io/guide/workspace-config
我想你设置了错误的相对路径.您的根文件夹应该是 reon-core
.因此,您需要像这样设置 stylePreprocessorOptions
:
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/"]
在build
和test
设置后,您可以在那里放入任何主题文件,例如:
After you set this, you can put in any theme file there and like:
./src/lib/tssource/theme.scss
并像 @import 'theme.scss';
这篇关于如何在Angular中缩短文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!