库的 stylePreprocessorOptions,我应该把它放在 angular.json 的什么位置?

Gre*_*eye 13 angular

我正在尝试使用stylePreprocessorOptions以便为库项目包含到我的变量文件夹的路径,如下所示:

"stylePreprocessorOptions": {
  "includePaths": [
    "styles/variables"
  ]
}
Run Code Online (Sandbox Code Playgroud)

然后我@import 'colors';在 scss 文件中使用。但它在做时不起作用ng serve

@import 'colors';
       ^
      Can't find stylesheet to import.
Run Code Online (Sandbox Code Playgroud)

这是 angular.json 中的完整库:

        "ui-table": {
            "root": "libs/ui/table",
            "sourceRoot": "libs/ui/table/src",
            "projectType": "library",
            "prefix": "xxx",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-ng-packagr:build",
                    "options": {
                        "tsConfig": "libs/ui/table/tsconfig.lib.json",
                        "project": "libs/ui/table/ng-package.json",
                        "stylePreprocessorOptions": {
                            "includePaths": [
                                "styles/variables"
                            ]
                        }
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": ["libs/ui/table/tsconfig.lib.json"],
                        "exclude": ["**/node_modules/**"]
                    }
                }
            },
            "schematics": {
                "@nrwl/schematics:component": {
                    "styleext": "scss"
                }
            }
        },

Run Code Online (Sandbox Code Playgroud)

如何stylePreprocessorOptions在 Angular 的库中使用?

谢谢!

Zai*_*inu 12

不在 angular.json 中。

在库的 ng-package.json 中包含scss文件夹的路径styleIncludePaths

"lib": {
    "entryFile": "src/public-api.ts",
    ...
    "styleIncludePaths": [
        "relative/path/to/scss/folder"
    ]
    ...
}
Run Code Online (Sandbox Code Playgroud)

最后从没有前缀路径的引用的scss文件夹中导入文件,如下所示

@import "filename";
Run Code Online (Sandbox Code Playgroud)