I’m trying to convert two Angular repos and their two shared submodule dependencies into one monorepo. To prepare for this process, I’ve tried to hoist the shared dependencies out of one of the projects and into a parent directory.
i.e, from:
/[repo-root]
tsconfig.json
angular.json
package.json
/node_modules
/src
/dependency1
/dependency2
to:
/[repo-root]
/main-app
tsconfig.json
angular.json
package.json
/node_modules
/dependency1
/dependency2
I’ve added the following to my tsconfig.json to remap these imports:
paths:
{
"@dependency1/*": ["../dependency1/*"],
"@dependency2/*": ["../dependency2/*"],
}
This works fine for importing things from these folders, but then the files in dependency1
& 2
can’t resolve the contents of node_modules
. Is there a way to specify that even “external” dependencies should try to resolve their imports using this local context?
I’m aware that solutions like Nx exist that solve the broader dependency management problems for monorepo projects, but I’d like to minimize the change risk and perform that migration after the “get all the stuff in the same git repo” migration, if possible.
user25527914 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
A monorepo follows this structure
/repo
/project1
/project2
/project-n
/lib
/package.json
/node_modules
/angular.json
Where the project folders are the different angular applications that are sharing dependencies.
Those dependencies can be in the form of third-party node_module packages or in-house libraries (/lib).
If the dependencies are in-house codes, then you should create an angular library and put the codes in it and just reference them in your application folders as you would reference any other code written in the application folders.
This is the command to add a library to your project.
ng generate library my-lib
You can find more info on Angular’s website
3