I want to build a nestjs backend which is used by a angular frontend application. Each of them for now in a single repository. I stumbled over nrwl-nx for monorepo tooling and am really intrigued to use it.
But my question now is: is it possible to have different apps in the workspace, but each as an own git submodule? Like so:
workspace_folder
|- apps
| |- application1 <--- git submodule 1
| |- application2 <--- git submodule 2
|- libs
|...
How would the process be to set them up correctly? Can it be done completely by the nx CLI? I couldn't find anything specific to that in the nx documentation.
git subtree allows you to nest a repository as a subdirectory inside another. It's one of the various options for managing project dependencies in Git projects. You add a subtree to an existing repository where the subtree is a reference to another repository URL and branch/tag when you wish to utilize it.
Why do we use Git submodules in the first place? In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate.
This .gitmodules file is one of multiple places where Git keeps track of the submodules in our project. Another one is .git/config, which now ends like this: And finally, Git also keeps a copy of each submodule’s .git repository in an internal .git/modules folder. All of these are technical details you don’t have to remember.
Checking for new changes in a submodule, for example, works like in any other Git repository: you run a git fetch command inside the submodule repository, possibly followed by something like git pull origin main if you want to indeed make use of the updates.
If a path is not provided, the submodule will default to the same name as its repository. If we look into the House repository, we’ll see the subdirectory Room repository like so:
Yes! I believe you can do this using Yarn workspace in conjunction with Nx tooling.
So in essence you need to navigate to your apps folder and run:
git submodule add https://github.com/[URL for your application 1] application1
git submodule add https://github.com/[URL for your application 2] application2
More Details here: https://blog.nrwl.io/dev-workflow-using-git-submodules-and-yarn-workspaces-14fd06c07964
An example will be like this: https://github.com/nrwl/nx-example-multirepo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With