Angular Cli: How to serve 2 applications?

I need 2 different applications in one project:

  • index.html> mainApp module
  • login.html> loginApp Module

(this is necessary for security reasons that Spring Security manages)

I vave angular-cli.json described below:

  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "styles.scss"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "login.html",
      "main": "login.ts",
      "test": "login-test.ts",
      "tsconfig": "login-tsconfig.json",
      "prefix": "login-app",
      "mobile": false,
      "styles": [
        "login-styles.scss"
      ],
      "scripts": [],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],

But expand only one (in the "apps" array).

If I invert Login at position [0], this works, but the mainApp module does not.

Apparently, the reason is because Angular Cli doesn't inject the generated JS files into the second html.

How can i solve this?

+4
source share
2 answers

UPDATE . Now several commands are supported by CLI - docs here

CLI Angular . , .

(, CLI).

+3

.angular-cli.json

"apps": [
    {
      "root": "src",
      "outDir": "../Application.Web.UI/wwwroot/app/Candidate",
      "assets": [
        "assets"
      ],
      "index": "index.html",
      "main": "main.candidate.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app_andidate",
      "styles": [ "share/css/material.scss" ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    },
    {
      "root": "src",
      "outDir": "../Application.Web.UI/wwwroot/app/Company",
      "assets": [
        "assets"
      ],
      "index": "index.html",
      "main": "main.company.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app_company",
      "styles": [ "share/css/material.scss" ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
0

Source: https://habr.com/ru/post/1663013/


All Articles