,

Create Modular Angular Apps using Nx Standalone Project Configuration

Posted by






Building Modular Angular Apps with the Nx Standalone Project Setup

Building Modular Angular Apps with the Nx Standalone Project Setup

When it comes to building large-scale Angular applications, modularization and code organization are key to maintaining a clean and maintainable codebase. Nx is a powerful tool that provides a set of extensible dev tools for monorepos, which can be used to build and manage multiple related applications and libraries in one workspace. In this article, we will explore how to set up a standalone Nx project and use it to build modular Angular apps.

Setting Up the Nx Project

To get started with building modular Angular apps using Nx, the first step is to set up a standalone Nx workspace. This can be done by running the following command in your terminal:

$ npx create-nx-workspace@latest my-nx-app --standalone

After running this command, you will be prompted to choose a JavaScript or TypeScript project. Once you have made your selection, Nx will create a new standalone workspace with the specified configuration.

Creating Modules and Libraries

With the standalone Nx workspace set up, you can start creating modules and libraries for your Angular app. This can be done using the following command:

$ nx generate @nrwl/angular:library my-library

This will create a new library in the “libs” directory of your Nx project, which can be used to organize and share code across different parts of your application. Similarly, you can also create modules using the following command:

$ nx generate @nrwl/angular:module my-module

Modules can be used to organize the components, services, and other resources that are specific to a particular feature or functionality of your app.

Building and Running the App

Once you have created the necessary modules and libraries for your Angular app, you can use Nx to build and run the application. Nx provides a set of commands that can be used to build, test, and serve the app. For example, you can run the following command to build the app:

$ nx build my-app

Similarly, you can use the following command to serve the app locally:

$ nx serve my-app

These commands can be used to build and run your Angular app, and Nx will handle all the necessary configurations and dependencies behind the scenes.

Conclusion

Building modular Angular apps with the Nx standalone project setup provides a powerful and flexible way to organize your code and manage related applications and libraries in a single workspace. By following the steps outlined in this article, you can set up a standalone Nx project and use it to build modular Angular apps with ease.


0 0 votes
Article Rating
17 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sam BIO
1 year ago

Bravo ❤ 🎉!!!

어쩌다가 외노자
1 year ago

Kudos

Aritro Biswas
1 year ago

nx graph is showing static load instead of dynamic. In browser page is lazy loading , anyone facing the same issue ?

Kiffin Gish
1 year ago

Great video, thanks. You create a shared ui component, but what would one use this for? What about shared header and footer components, would they be placed in here also. What about a shared material library?

Martin Pultz
1 year ago

I noticed that their were some merges around eslint v8 to v9. I thought maybe running the migration from 16.5 to 16.6 might perform that update. Is that something that hasn't quite made it's way into an Nx release, but eventually would self update or do I need to perform that update myself? Feels like the answer is yes it will update, but wasn't sure after my last nx migrate. Cheers! Reply

Santon Motho
1 year ago

OMG I finally SEE the value of Nx! This was a gem of a video. I might be assuming too much right now, but I'm excited to explore Nx a lot more now. Please keep uploading such videos

Igor R
1 year ago

Regrettably, possessing programming knowledge and familiarity with the topic does not automatically translate to being an effective teacher. Alongside technical expertise, proper communication skills and clear pronunciation are imperative to ensure that your audience is on the same page and fully engaged in the learning process

Leonardo Camargo
1 year ago

If I need to create a small module within the application.

For example:

Customer module, which has only the following components:

Registration form page;

Edit form page;

Page of the table with the list of customers.

NX will create a local library of clients.

As this is a small module, won't separating it into a local library make the project too big and cumbersome?

Besides, as a local library will be, instead of installing its own dependencies, is it okay if I use the dependencies globally in the application?

Matheus82
1 year ago

Como introduzir isso no IONIC…???

Carlos Abud
1 year ago

Great video man, keep it up!

Muhamed Karajic
1 year ago

We want for the CI also a video 🙂

Carnaru Valentin
1 year ago

I really don't understand why you don't create many projects to use the shared modules. Your scenario can be done simpler with angular cli and don't need an extra layer like NX. I miss something?

Harvey Daclan
1 year ago

Hi Juri, thanks for this tutorial. I usually have a shared theme in my projects. How do I share scss files from one library to another? Is this possible in both standalone and monorepo projects?

Nemanja Zivaljevic
1 year ago

Can someone help me with this? I have multiple angular apps that use UI components from libs file. The problem is that nx doesn't tree shake them, it bundle everithing.

Ankush Kalia
1 year ago

Can i convert a standalone app to monorepo setup in future?

ปลาทูน่า
1 year ago

Hi, I'm new to NX console and I've been trying to follow this tutorial
I have a few questions:

Regarding the shared/ui directory, should I place shared UI components like a navbar or footer there? like shared/ui/src/lib/ui-navbar right ?

If I want to create a UI for a feature, what steps should I follow?