Angular 6生产模式会删除Bootswatch主题吗?

时间:2018-06-27 15:10:07

标签: angular bootswatch

我有一个使用Bootstrap 4和Bootswatch主题(Lumen)的Angular 6应用。当我使用ng serve在测试环境中编译站点时,样式和主题可以正常工作,而当使用ng build为我的nginx Web服务器进行编译时,样式和主题也可以正常工作。但是,当以Web服务器的生产模式(ng build --prod)进行编译时,基本的Bootstrap样式有效,但是Bootswatch主题显然未加载或无效。该网站看起来像普通的Bootstrap 4。

我在Angular CLI中的安装过程是:

npm install --save bootstrap
npm install --save @ng-boostrap/ng-bootstrap
npm install bootswatch

我的angular.json的“样式”部分如下:

"styles": [
  "node_modules/bootstrap/dist/css/bootstrap.min.css",
  "node_modules/bootswatch/dist/lumen/bootstrap.min.css",
  "src/styles.css"
],

杀死我主题的生产模式是怎么回事?我该如何解决?

编辑:我的package.json根据评论的要求:

{
  "name": "neo-analytics",
  "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": "^6.0.3",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@ng-bootstrap/ng-bootstrap": "^2.1.1",
    "bootstrap": "^4.1.1",
    "bootswatch": "^4.1.1",
    "core-js": "^2.5.4",
    "rxjs": "^6.2.1",
    "rxjs-compat": "^6.2.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

3 个答案:

答案 0 :(得分:1)

您可以尝试通过添加styles.css而不是直接在angular.json的styles []下添加内容:

styles.css

@import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
@import "../node_modules/bootswatch/dist/lumen/bootstrap.min.css";

angular.json

"styles": [
  "styles.css"
],

答案 1 :(得分:0)

肯定是:

"styles": [
   "src/styles.css"
],

答案 2 :(得分:0)

我知道这是一个较晚的答案,但是公认的答案是错误的。您应该用Bootswatch一替换原来的bootstrap.min.css。 Bootsatch的CSS文件应该替换原始的Bootstrap CSS文件。因此,在您的angular.json中,您只需要具备以下条件:

"styles": [
  "node_modules/bootswatch/dist/lumen/bootstrap.min.css",
  "src/styles.css"
],