Abhijith Dev
Abhijith Dev

Reputation: 1

How can I pack one library into another JS library using npm?

I am creating an angular library, which is internally using the vtk.js library. I tried adding vtk.js as a peer dependency. But on installing my custom package, it is showing a warning to install vtk.js as well.

Is there any way I can make sure that the vtk.js package will also get packed inside my angular package?

Upvotes: 0

Views: 140

Answers (1)

Oleksandr Sakun
Oleksandr Sakun

Reputation: 462

You can express dependencies of your library in a 2 ways (actually 3 but devDependencies is pretty self-explained so we omit them)

  1. peerDependencies - you can use this type of dependency if you need to express the following things:
  • Your library is depends on some specific version of another library
  • Your library will have a conflicts in case node_module contains few versions of the dependency (because of so called transitive dependency this case is possible)
  • You wish a developer decide on what version of the dependency to use

As you mentioned peerDependencies is not installed automatically, instead it will warn a consumer of you lib about missing dependency or incompatible version of it

2.dependencies - use dependencies if you do not care about the cases described above. Having vtk.js here guarantee that it will be installed automatically for every consumer of your lib

Upvotes: 1

Related Questions