【发布时间】:2021-09-17 05:32:19
【问题描述】:
我有一个 Angular 库,其中包含我想要使用的样式,就好像它们是应用程序的一部分一样。 我尝试使用 includePaths 来通过在 angular.json 中使用以下配置来做到这一点:
{
projects: {
"my-project": {
"root": "",
"sourceRoot": "src",
"prefix": "mp",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/selenium-agent-ui",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"stylePreprocessorOptions": {
"includePaths": [
"src/assets",
"node_modules/ui-library/assets"
]
},
...
在我的 scss 样式文件中,我想写以下内容:
@import "assets/ui-library-folder/ui-library-scss-file"
但是,我收到以下错误:
Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
╷
1 │ @import "assets/ui-library-folder/ui-library-scss-file";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
src\app\app.component.scss 1:9 root stylesheet
文件夹结构:
my-app
|--node_modules
| |--ui-library
| | |--assets
| | | |--ui-library-folder
| | | | |--ui-library-scss-file.scss
|--src
| |--app
| | |--app.component.scss
| |--assets
| | |--...
|--angular.json
|--package.json
|--tsconfig.json
|--tsconfig.app.json
我已尝试根据这些链接中提供的解决方案工作,但它们不起作用:
Angular 8 ignores includePaths
Shorten SCSS import path in Angular 7
【问题讨论】: