相关疑难解决方法(0)

如何将全局样式添加到angular 6/7库

我试图以与在角度应用程序中相同的方式添加全局样式,但它完全不起作用。

我的库的名称是example-lib,所以我添加styles.css/projects/example-lib/。我在主angular.json文件中添加了样式:

...
"example-lib": {
  "root": "projects/example-lib",
  "sourceRoot": "projects/example-lib/src",
  "projectType": "library",
  "prefix": "ngx",
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-ng-packagr:build",
      "options": {
        "tsConfig": "projects/example-lib/tsconfig.lib.json",
        "project": "projects/example-lib/ng-package.json",
        "styles": [
          "projects/example-lib/styles.css" <!-- HERE 
        ],
      },
...
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用命令构建库时:

ng build example-lib

我收到错误消息:

Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(styles)
Run Code Online (Sandbox Code Playgroud)

我想这是在单独的库中添加全局样式的另一种方法。有人可以帮助我吗?

css styles angular angular-library

23
推荐指数
3
解决办法
8476
查看次数

标签 统计

angular ×1

angular-library ×1

css ×1

styles ×1