在部署之前,我的Angular项目在Bootstrap 3.3.7(项目所需)上运行良好。 Bootstrap无法识别,因此我回去调整项目中的某些文件,现在Bootstrap将不再在本地环境中工作。我已经为此花了两天时间,似乎找不到解决方法。
My angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "/",
"projects": {
"public": {
"root": "",
"sourceRoot": "public/src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "public/dist/public",
"index": "public/src/index.html",
"main": "public/src/main.ts",
"polyfills": "public/src/polyfills.ts",
"tsConfig": "public/src/tsconfig.app.json",
"assets": [
"public/src/favicon.ico",
"public/src/assets"
],
"styles": [],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "public/src/environments/environment.ts",
"with": "public/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": "public:build"
},
"configurations": {
"production": {
"browserTarget": "public:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "public:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "public/src/test.ts",
"polyfills": "public/src/polyfills.ts",
"tsConfig": "public/src/tsconfig.spec.json",
"karmaConfig": "public/src/karma.conf.js",
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"public/src/styles.css"
],
"scripts": [],
"assets": [
"public/src/favicon.ico",
"public/src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"public/src/tsconfig.app.json",
"public/src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"public-e2e": {
"root": "public/e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "public/e2e/protractor.conf.js",
"devServerTarget": "public:serve"
},
"configurations": {
"production": {
"devServerTarget": "public:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "public/e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "/"
}
My package.json
{
"name": "portfolio",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot -prod"
},
"private": true,
"dependencies": {
"@angular/animations": "7.2.0",
"@angular/cli": "7.1.4",
"@angular/common": "7.2.0",
"@angular/compiler": "7.2.0",
"@angular/compiler-cli": "7.2.0",
"@angular/core": "7.2.0",
"@angular/forms": "7.2.0",
"@angular/http": "7.2.0",
"@angular/platform-browser": "7.2.0",
"@angular/platform-browser-dynamic": "7.2.0",
"@angular/router": "7.2.0",
"core-js": "^2.4.1",
"express": "^4.16.2",
"rxjs": "^6.3.3",
"typescript": "3.2.2",
"ngx-bootstrap": "^3.1.2",
"bootstrap": "^3.3.7",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/language-service": "7.2.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"enhanced-resolve": "^3.3.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0"
},
"engines": {
"node": "6.11.0",
"npm": "3.10.10"
}
}
My dist/publix/index.html
<!doctype html>
<html lang="en">
<head>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="polyfills.js"></script>
<script type="text/javascript" src="vendor.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
答案 0 :(得分:0)
尝试本地化引导程序类而不是CDN
答案 1 :(得分:0)
弄清楚了。我在本地安装了bootstrap,不得不调整angular.json中的“样式”以指向正确的目录。
"styles": [
"public/src/styles.css",
"./bootstrap-3.3.7-dist/css/bootstrap.min.css"
],