Quick Intro about Angular Workspaces

Senbagaraman MSenbagaraman M
2 min read

Angular workspaces or angular multi-site applications are an effective way of creating and maintaining multiple website inside a single project repository.

Mono Repo :

A mono repo is a single repository that contains all the code for an organization or project. It is a single source of truth for the entire organization's code base. The Monorepo pattern is used to set up one workspace with multiple projects and libraries sharing the same dependencies across all projects.

Angular Workspaces:

Angular Multisite Workspace is used to set up one workspace with multiple projects and libraries sharing the same dependencies across all projects.

As stated earlier, A monorepo is a massive codebase containing independent projects, whereas a monolithic application combines sub-projects into one large project. When we refer to a “monolith” here, we are referring to a monolithic application, which is a single-tiered application designed as a single service. A monolith can be managed in a mono repo1.

In contrast, multisite workspace is an Angular feature that allows you to manage multiple projects in the same workspace2. It is used when you have multiple applications that share common code and libraries. Each application has its own source code and configuration files but shares the same node_modules folder2.

Create Angular Workspace locally:

  1. Create an application using the following commands,

     ng new rams-workspace --no-create-application
    
  2. Main application has been created, create two applications,

      ng generate application application1
      ng generate application application2
    
  3. Now create a sharedlib, which may host the components shared across the application,

     ng g library firstlibrary
    
  4. The components inside the application can be created by the following code,

ng generate component firstComponent  --project=application1
  1. The components inside the library can be created using the following commands,

     ng g c HelloComponent --project=firstlibrary
    

New component in Shared Library

Export the same in the module, to be consumed in the application

Export the shared component in library

Consume the same in the application as normal

Import the shared lib

The structure of the applications will be as follows,The following image explains the two sample applications

Project Structure

The above example has been added with fully working code in the github repository

https://github.com/senbagaraman04/rams-workspace

Sources:

  1. What Is a Monorepo? | Perforce

  2. Monorepo vs Multi-Repo: Pros and Cons of Code Repository Strategies (kinsta.com)

0
Subscribe to my newsletter

Read articles from Senbagaraman M directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Senbagaraman M
Senbagaraman M