angular6 如何引入第三方css库

参考

  1. angular4引入其它css文件

解决办法

将 src/styles.css 中引入如需代码

@import "./assets/bootstrap/css/bootstrap.min.css";

为什么是修改src/styles.css

这是因为在angular.json配置文件中添加了样式引入该文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "googleSearch": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/googleSearch",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "src/assets/bootstrapvalidator/js/bootstrapValidator.min.js",
              "src/assets/js/masonry.pkgd.min.js",
              "node_modules/datatables.net/js/jquery.dataTables.js"
            ]
          },
          "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
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "googleSearch:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "googleSearch:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "googleSearch:build"
          }
        },
        
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },    
  },
  "defaultProject": "googleSearch"
}

代码片段

"styles": [
	"src/styles.css"
],
阅读更多

没有更多推荐了,返回首页