如何在Angular 5中切换全局样式?

时间:2018-04-19 16:32:28

标签: css angular typescript bootstrap-4 bootstrapping

我有两个Angular 5项目。首先是登录和注册的登录页面,第二个是应用程序的主面板。我有一个问题,因为它们都使用angular.cli中声明的不同全局样式。

例如,登录页面使用来自node_modules的Bootstrap,主面板使用来自资产的Bootstrap。它们是不同的并且相互覆盖。即使我试图将这两个应用程序的每个组件添加到适当的CSS中,它们也无法正常工作,因为它们的组件在全局样式中需要一个正确版本的node_modules。

所以取决于我使用全局样式(登录页面或主面板)的哪个项目只有这一页正常工作。第二个是样式存在问题,许多组件看起来和工作都不正常。 Node_modules只是一个例子。在angular.cli中还声明了其他样式。

我的两个应用程序的角度cli看起来如下所示。我需要连接它们只有一个应用程序。有什么方法可以解决这个问题吗?

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "frontend"
  },
  "apps": [
    {
      "name":"home",
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index-home.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/bootstrap/dist/js/bootstrap.js",
        "../node_modules/arrive/src/arrive.js",
        "../node_modules/moment/moment.js",
        "../node_modules/chartist/dist/chartist.js",
        "../node_modules/bootstrap-notify/bootstrap-notify.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "name":"landing-page",
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index-landing-page.html",
      "main": "main2.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "assets/landing-page/sass/paper-kit.scss",
        "assets/landing-page/css/demo.css",
        "assets/landing-page/css/nucleo-icons.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.slim.min.js",
        "../node_modules/popper.js/dist/umd/popper.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

0 个答案:

没有答案