Create Multiple Angular Apps in One Project
In this article, we will demonstrate how to develop and arrange several apps in a single Project or Workspace. Since version 6, we may establish a multi-project workspace in the Angular CLI to manage numerous Angular apps. To start with, we create a blank workspace. An assortment of Angular projects, apps, or libraries makes up a workspace. Later, we can expand the workspace to accommodate more projects.
Advantages
Having multiple Angular apps in a single project has many benefits.
- One is that you do not have to perform each app's time-consuming npm install.
- All the other applications share the node modules folder, which conserves disc space.
- Any software can easily be upgraded to the newest version.
- an individual source-control repository (like git).
Create the Empty Workspace
Using the ng new app> Angular CLI command, we build a new app. A basic Angular app named "new" is created in the workspace's src folder. The initial app no longer gets created when the createApplication="false" option, introduced in Angular 7, is used. It merely establishes the workspace.
ng new MultipleApps --createApplication="false" cd MultipleApps
Add a new Project to Workspace
ng generate application gettingStarted
Run the App
- NG serve gettingStarted should be used.
- Use the ng serve --project flag. --project="gettingStarted"
- Locate the defaultProject in angular.json, rename it to gettingStarted, and then execute ng serve.
Add Another Project to the workspace
ng generate application exampleApp
Run the App
ng serve exampleApp
ng serve --project="exampleApp"
Building the App for Production
ng build --prod --project="gettingStarted" ng build --prod --project="exampleApp"
Folder Structure
projects folder
dist folder
Angular.json
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", <== location of the apps "projects": { "gettingStarted": { //This section contains the setting for the gettingStarted project }, "exampleApp": { //This section contains the setting for the exampleApp project }}, "defaultProject": "gettingStarted" <== name of the default project }