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

问题描述 投票:6回答:1

我正在尝试使用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

谢谢!

angular
1个回答
0
投票

不在angular.json中。

在ng-package.json的styleIncludePaths中包含路径:

"lib": {
    "entryFile": "src/public-api.ts",
    ...
    "styleIncludePaths": [ <---------
        "src/lib/scss" <-------------
    ]
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.