Reputation: 7436
I have a angular library installed in my angular application. So the library has all the angular dependencies such as @angular/common, @angular/core etc.
I want to use a single version of angular dependencies in multiple applications. So i am moving angular dependencies to a centralized angular library.
Now I want to make use of the library's angular dependencies in my current angular application. Without adding angular dependencies directly in current project.
Is this achievable? if yes, how? pls suggest
Upvotes: 0
Views: 57
Reputation: 57521
This is a bad idea because it causes tight coupling of the library and the application, so that both cannot be split. If you must do it, then go for the library located in the same place as the application, so that both of them share the same node_modules
. Then when you modify the library, you can build it and install (to use it).
If you must use it separately, you can try adding the Angular files in the public-api.ts
file so that it's visible to the applications importing it. Mind you, this is a lot of work, since Angular has multiple imports. I would not recommend this approach.
Upvotes: 0
Reputation: 3521
When you install a library that has dependencies, those dependencies get installed too.
Your IDE does not offer them in intellisense because they're not in the package.json file, but they do exist (check your node_modules folder to see it)
You can just import them as if they were installed and use them. You will just be missing the autocompletion when you write the library name.
That being said, this is a terrible idea for several reasons and you should refrain from doing so. If you really want to have the same version of a library, just either do it by hand, or create a schematic that you can publish and use in every project.
Upvotes: 1