css - 如何访问本地安装的 NPM 包的 CSS
问题描述
我已经下载并安装了 NPM 包,但我无法访问已安装包的 css。我正在使用这个包。有人可以帮我吗?根据文档,我需要添加以下 css 文件。
<link rel="stylesheet" href="css/grid.css" /><!-- Opt-in Default Grid -->
<link rel="stylesheet" href="css/bootstrap4-scoped.css" /><!-- Optional scoped version of Bootstrap 4 -->
<link rel="stylesheet" href="css/styles-nw.css" /><!-- Core Styles (which already includes all needed Bootstrap 3 styles) -->
<link rel="stylesheet" href="css/bootstrap4-override.css" /><!-- Optional Bootstrap 4 Overrides -->
我在 Angular 项目中添加了 index.html:
<!doctype html>
<html lang="en" class="cpl-scope">
<head>
<meta charset="utf-8">
<title>IhsPoc</title>
<link rel="stylesheet" href="css/grid.css" /><!-- Opt-in Default Grid -->
<link rel="stylesheet" href="css/bootstrap4-scoped.css" /><!-- Optional scoped version of Bootstrap 4 -->
<link rel="stylesheet" href="css/styles-nw.css" /><!-- Core Styles (which already includes all needed Bootstrap 3 styles) -->
<link rel="stylesheet" href="css/bootstrap4-override.css" /><!-- Optional Bootstrap 4 Overrides -->
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
包.json
{
"name": "ihs-poc",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"csspatternlibrary3": "file:node_modules/csspatternlibrary3@3.0.3",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.20",
"@angular/cli": "~8.3.20",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@types/node": "~8.9.4",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
}
npm 包入口可用但无法访问 css
"csspatternlibrary3": "file:node_modules/csspatternlibrary3@3.0.3"
解决方案
您必须将其添加到angular.json
文件中。将文件路径添加到"styles": []
例如:"styles": ["node_modules/foo/bar.css"]
推荐阅读
- android - 用于中文(allwinner arm cpu)构建的 AOSP
- php - 如何将大量内容从多维数组存储到 mysql 数据库中?
- select - 样式=“宽度:100%;” 不适用于
- django - ModelForm 忽略 MultiChoice 字段的 Django 初始值
- java - StartupError > 如果 XML 文件有 ${<>} 则服务器未启动
- json - Angular 4/5 - 根据标题过滤下拉菜单
- jq - 过滤带有句点的属性名称
- angularjs - .htaccess 不重定向(版本 1.6.10)
- html - 引导程序中具有不同图像大小的图像库
- delphi - Delphi - 使用 TEdit.tagObject 指向另一个对象