库的stylePreprocessorOptions,应该在哪里放置angular.json?

时间:2019-11-26 14:33:20

标签: angular

我正在尝试使用stylePreprocessorOptions来为我的变量文件夹添加路径,用于库项目,例如:

"stylePreprocessorOptions": {
  "includePaths": [
    "styles/variables"
  ]
}

然后我在scss文件中使用@import 'colors';。但是在执行ng serve时不起作用:

@import 'colors';
       ^
      Can't find stylesheet to import.

这是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"
                }
            }
        },

如何在Angular的库中使用stylePreprocessorOptions

谢谢!

1 个答案:

答案 0 :(得分:6)

不在angular.json中。

在图书馆的ng-package.json

中,用from some_other_app.models import client class Invoice(models.Model): user = models.ForeignKey(client,on_delete=models.CASCADE,related_name="userpostchallenge") 包含 scss 文件夹的路径
styleIncludePaths

最终从引用的 scss 文件夹中导入文件,不带前缀路径,如下所示:

"lib": {
    "entryFile": "src/public-api.ts",
    ...
    "styleIncludePaths": [
        "relative/path/to/scss/folder"
    ]
    ...
}