4

I need 2 different apps on same project:

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

(this is required for security reasons managed by Spring Security)

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 only deploy the first one (on "apps" array).

If I invert Login at position [0], this works, but mainApp Module doesn't.

Apparently the reason is, Angular Cli doesn't inject created JS files on the second html.

How can I resolve this?

2 Answers 2

3

UPDATE: Multiple apps are supported now by the CLI - docs are here

Currently the Angular CLI does not support multiple apps. It is something that will be supported in the future.

For now you could work under separate directories (aka separate CLI projects).

Sign up to request clarification or add additional context in comments.

2 Comments

You're welcome. If you do move away from the CLI just be aware that you will need to create your own build process for both projects from the ground up (outside the CLI).
The --app option is now available in ng build etc.
0

You can edit your .angular-cli.json file and setup multiple apps

"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"
      }
    }
  ],

2 Comments

Can you specify what ports to run each app on?
Not in the config. But you can run your app on next available port if 4200 is already in use ng serve --app 1 --port=0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.