0

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

2
  • What are you trying to do, specifically? This doesn't make much sense. Commented Jun 25, 2024 at 7:18
  • I want to use a single version of angular dependencies in multiple applications. So i am moving angular dependencies to a centralized angular library. All other projects will add this library. so angular bundle also needs to be integrated with cyentralized librar Commented Jun 25, 2024 at 7:24

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Your solution will prevent tree shaking.
@MGX please be clear, which solution there are two here
The second one sorry

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.