Quick Intro about Angular Workspaces
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:
Create an application using the following commands,
ng new rams-workspace --no-create-application
Main application has been created, create two applications,
ng generate application application1 ng generate application application2
Now create a sharedlib, which may host the components shared across the application,
ng g library firstlibrary
The components inside the application can be created by the following code,
ng generate component firstComponent --project=application1
The components inside the library can be created using the following commands,
ng g c HelloComponent --project=firstlibrary
Export the same in the module, to be consumed in the application
Consume the same in the application as normal
The structure of the applications will be as follows,The following image explains the two sample applications
Github Link:
The above example has been added with fully working code in the github repository
https://github.com/senbagaraman04/rams-workspace
Sources:
Subscribe to my newsletter
Read articles from Senbagaraman M directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by