19

How to create multiple application under single project in Angular 6? In new angular.json file, there is no "app":[] array, where before we used to create/add multiple applications manually. Also there is no proper documentation I found at this stage, which elaborate how to create multiple application in single project. Any help would be appreciated. Thank you.

BhargavG
  • 896
  • 1
  • 6
  • 15
  • 1
    But there is a projects array. And there is this command: https://github.com/angular/angular-cli/wiki/generate-application – JB Nizet Jun 30 '18 at 13:15
  • Hey did you manage to sovle and do you have a sample project i can look at – Kay Aug 15 '18 at 11:39
  • @Kay Please checkout martzcodes answer, I have follow those steps in my project. As we've mention previously, project structure is still not up to the mark but this is what Angular team provide at the moment. – BhargavG Aug 20 '18 at 09:21

4 Answers4

16

Like @JB Nizet said... you can use generate application (https://github.com/angular/angular-cli/wiki/generate-application)

ng generate application <application-name>

to generate an application in the projects folder, and then serve it using

ng serve --project <application-name>

Similarly, you can create component libraries using ng generate library (https://github.com/angular/angular-cli/wiki/generate-library)

ng generate library <library-name>

For common components used between projects. Both of which get installed into the /projects folder unless you changed the projects root when doing ng new.

martzcodes
  • 404
  • 5
  • 16
  • Thanks for the reply. Actually I used `ng generate application ` to create new app inside my existing project, but now I am having some problem in project structure. When I created my project, It follows this structure; project-name -> project-name -> src -> app, Now when I create through ng generate, It create new "project" directory and inside that there is new app. So I got one app in "project" folder and another outside that folder, which in my opinion is not a good structure. I obviously can't move my original app inside project folder. Is there any other way? – BhargavG Jul 02 '18 at 03:52
  • Funny enough... but I created this exact issue on github the other day: https://github.com/angular/angular-cli/issues/11402 and https://stackoverflow.com/questions/51090592/how-to-create-a-mono-repo-project-structure-with-angular-cli-6-x – martzcodes Jul 02 '18 at 14:06
5

If you have a project with multiple applications, use angular upgrade guide (https://update.angular.io/) instructions to upgrade your application. One of the step while performing upgrade is to run

ng upgrade @angular/cli

(once you upgrade your @angular/cli to v6+). This will generate new angular.json file using your existing angular-cli.json file for multiple applciations.

Upgrade Angular CLI

OR

Manually edit your angular.json to add new application to the existing project. Editing JSON file for Another Application.

ng serve --project="second-app"

ng build --prod --project="second-app" // build prod app
ilogs
  • 111
  • 3
  • 1
    No need to do that manually now, They gave us `ng generate` command to create new application. But the project structure in which it is created is not proper and little bit confusing too, in my honest opinion. Please read comments in @martzcodes reply for the same. – BhargavG Aug 02 '18 at 05:25
2

Create a workspace with --createApplication="false"

ng new MultipleApps --createApplication="false"
cd MultipleApps  

use ng generate application to add as many apps

ng generate application app1
ng generate application app2

To run the app use the ng serve

ng serve app1

Source Angular multiple projects

0

To get my application working I removed everything from the main app.component.html file except for the

<router-outlet></router-outlet>. 

Then I added a route to my app-routing.module.ts file:

{path: '**', redirectTo: 'newApp'}

with nothing in the main app.component the application will automatically redirect to your 'newApp'

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
Austin752
  • 29
  • 8