How to Create Multiple Apps in the Same Workspace in Angular 6

One of the most talked-about features in Angular 6 is support for multiple apps within the same workspace. Here's a quick how-to on how to do this.

First, this assumes you're using the Angular CLI. When you create a new app using the CLI, it will actually create two projects for you: one having the name you specified when you created the project, and another with "-e2e" appended to the name. This project is for end-to-end tests. These two projects will be listed in the angular.json file under the projects node. The code for the project you asked the CLI to create will be located in (app name)\src\app, and the code for the e2e project will be located in (app name)\e2e\src.

But what if you want to add another project?

This is simple. Using the CLI, from within your project's root directory, execute ng generate application (name of your new app).

For example:
ng generate application another-app

This will do the following:

  • Adds a new folder called projects under your app's root directory, under which it will add two sub-folders with the generated application files: one with the name of the new app you created, and another with the "-e2e" appended to it. Note that it places this e2e project here, and not in the directory that your other e2e project lives in.
  • Updates angular.json to include the two new applications it created to the projects node.
You can run Node scripts against these projects just as you would a normal Angular project, just specify the --project parameter. 

For example:
ng build --project another-app
ng serve --project another-app

They can even have their own node_modules folders, but by default they will use the node_modules folder that the parent/original project uses. They'll also inherit any Node modules from the parent/original project.

Hopefully, this enough to get you started on creating multiple apps in the same workspace using Angular 6!

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

Silent Renew and the "login_required" Error When Using oidc-client

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

How to Determine if a Column Exists in a DataReader