Angular Multiple Apps in One Project Using Angular CLI

In this guide, we will show you how to organize multiple apps in one Project or Workspace. The Angular CLI since version 6 allows us to create a multi-project workspace to manage multiple apps. We do that first by creating an empty workspace. A Workspace is a collection of Angular apps, projects or libraries. Later we can add multiple projects to the workspace.

Applies to: Angular 6 to the latest edition i.e. Angular 8. Angular 9, Angular 10

Advantages

There are several advantages of having Angular Multiple Apps in One Project.

  1. One is you do not have to run the time consuming npm install for every app.
  2. The node_modules folder is shared with all the other apps saving disk space.
  3. All the apps can be updated to the next version easily.
  4. A single source-control repository (such as git).

Create the Empty Workspace

We create a new app using the ng new <new> Angular CLI command. It creates and workspace with an initial Angular app with the name <new> in the src folder. The createApplication=”false” option introduced in Angular 7 now stops the creation of the initial app. It only creates the workspace

The above command creates folder with the name MultipleApps and configures the workspace. It does not create any apps.

Creating Multiple App under a Single Project Workspace
Creating Multiple App under a Single Project Workspace

Add a new Project to Workspace

Now, to create a new app under the workspace, we need to use the ng generate application command The first app created is marked as the default app.

Creating the App under a workspace
Creating the App under a workspace

If you use the ng new inside the workspace, it will throw the following error.

The new command requires to be run outside of a project, but a project definition was found at “D:\MultipleApps\angular.json”

Run the App

There are three ways in which you can run the app.

One is to use the ng serve gettingStarted

Use the --project flag ng serve --project="gettingStarted"

Open the angular.json and locate the defaultProject and change the name of the project to gettingStarted and run ng serve

ng serve
ng serve

Add Another Project to the workspace

To create another app, run the ng generate application again.

Run the App

And use the ng serve to run it


Best Angular Books
The Top 8 Best Angular Books, which helps you to get started with Angular  

Building the App for Production

Use ng build to build the app with --project option.

Folder Structure

The folder structure is similar to the Single App workspace, except for the following

The folder structure of Multiple Apps under a Single workspace
The folder structure of Multiple Apps under a Single workspace

projects folder

The src folder is gone. Instead, we have a projects folder. Each app we create gets its own folder under the projects folder.

dist folder

The dist folder now has a folder for each of the new app.

Angular.json

The angular.json, contains the configuration settings for the workspace. Here is the shortened version of Angular.json for the above code.

newProjectRoot: node points to the location of the projects folder.

projects: contain a section for each app in the workspace. Each section contains configuration for the compiler.

defaultProject: The default project use, when you run the ng serve, ng build etc.

References

Angular File structure

Source Code

https://github.com/tekTutorialsHub/Angular-MultipleApps

Summary

In this guide, we learned how to organize multiple apps in one single workspace/Project in Angular.

1 thought on “Angular Multiple Apps in One Project Using Angular CLI”

  1. Could you please share some light how to deploy them in firestore both application sitting on same database
    and accesses with their own url like app1.com and app2.com

    regards,
    Jayram

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top