外部CSS文件无法与Angular Project集成

时间:2019-02-26 10:25:31

标签: css angular bulma

   strong text    {
      "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
      "version": 1,
      "newProjectRoot": "projects",
      "projects": {
        "first": {
          "root": "",
          "sourceRoot": "src",
          "projectType": "application",
          "prefix": "app",
          "schematics": {},
          "architect": {
            "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                "outputPath": "dist/first",
                "index": "src/index.html",
                "main": "src/main.ts",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.app.json",
                "assets": [
                  "src/favicon.ico",
                  "src/assets"
                ],
                "styles": [
                  "node_modules/bulma/css/bulma.css",
                  "src/styles.css"
                ],
                "scripts": [],
                "es5BrowserSupport": true
              },
              "configurations": {
                "production": {
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts",
                      "with": "src/environments/environment.prod.ts"
                    }
                  ],
                  "optimization": true,
                  "outputHashing": "all",
                  "sourceMap": false,
                  "extractCss": true,
                  "namedChunks": false,
                  "aot": true,
                  "extractLicenses": true,
                  "vendorChunk": false,
                  "buildOptimizer": true,
                  "budgets": [
                    {
                      "type": "initial",
                      "maximumWarning": "2mb",
                      "maximumError": "5mb"
                    }
                  ]
                }
              }
            },
            "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
                "browserTarget": "first:build"
              },
              "configurations": {
                "production": {
                  "browserTarget": "first:build:production"
                }
              }
            },
            "extract-i18n": {
              "builder": "@angular-devkit/build-angular:extract-i18n",
              "options": {
                "browserTarget": "first:build"
              }
            },
            "test": {
              "builder": "@angular-devkit/build-angular:karma",
              "options": {
                "main": "src/test.ts",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.spec.json",
                "karmaConfig": "src/karma.conf.js",
                "styles": [
                  "src/styles.css"
                ],
                "scripts": [],
                "assets": [
                  "src/favicon.ico",
                  "src/assets"
                ]
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": [
                  "src/tsconfig.app.json",
                  "src/tsconfig.spec.json"
                ],
                "exclude": [
                  "**/node_modules/**"
                ]
              }
            }
          }
        },
        "first-e2e": {
          "root": "e2e/",
          "projectType": "application",
          "prefix": "",
          "architect": {
            "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "e2e/protractor.conf.js",
                "devServerTarget": "first:serve"
              },
              "configurations": {
                "production": {
                  "devServerTarget": "first:serve:production"
                }
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": "e2e/tsconfig.e2e.json",
                "exclude": [
                  "**/node_modules/**"
                ]
              }
            }
          }
        }
      },
      "defaultProject": "first"
    }

我开始使用Angular,当我开始一个新项目时,在外部CSS文件集成时遇到了问题。目前,我正在将Bulma用于外部CSS。根据文档,我按照步骤进行操作,但无法获得所需的输出。在第一步中,我使用“ npm install Bulma”在项目中安装了外部CSS。接下来,我从node_modules复制了Bulma CSS的路径,并以angular.json样式指定了路径 我尝试了其他外部CSS文件,但出现了同样的问题。

3 个答案:

答案 0 :(得分:0)

在引用前添加./。像这样

./node_modules/bulma/css/bulma.css

答案 1 :(得分:0)

也许尝试在Styles.css中导入bulma.css。像这样

@import '~bulma/css/bulma.css';

答案 2 :(得分:0)

通往布尔玛的道路似乎很好,我在这段代码中没有看到任何问题。您重新启动了ng serve吗?不监视angular.json文件,并且不会持续构建该文件。