Create your Standalone Angular Library in 10 minutes

2 Likes

Thanks for this article! We had some doubts about how to add other dependencies than Angular dependencies to our Angular lib’s package.json. After reading through the section “Adding dependencies” the doubts are gone :slight_smile:

But I am not sure I understand why you need to add the peer dependencies as dev dependencies. Is this because you created a library without an Angular app (ng new my-lib --create-application=false)?

In our case, we just added the lib’s peer dependencies to the app’s dependencies (the app we created with the lib: --create-application=true) so they are installed with npm install. Also we build the lib from the project root: ng b --prod my-lib.

I’m glad the article helped you!

You’re right, in the article it is necessary to add peerDependencies also in devDependencies because the library is in its own workspace (with --create-application=false option).

In your case, both the app and the library are in the same workspace. When you build the library, if a peer dependency isn’t in the library node_modules, node will look up in the workspace node_modules which contains your app dependencies.

To sum up, it depends if your app and library share the same angular workspace.

1 Like