A
A
Alexander Bogdanov2020-05-20 11:11:47
JavaScript
Alexander Bogdanov, 2020-05-20 11:11:47

What is the correct way to split npm package dependencies?

The gist is this:
There is a certain functional module that is delivered to the final application using npm as a separate package in node_modules. Like any modern js application, it has a number of dependencies, some of which are needed only for assembly, and the other part is used in the package itself during assembly. The first, respectively, are devDependencies, and the second are dependencies. At the same time, the package itself is delivered already assembled, that is, in fact, in one bundle file with the ability to import from it. However, when installing the package, it pulls with it its dependencies, which are not needed by the final application, since they are not used in it, but this is the npm mechanics and they write on the Internet that such dependencies should be in the save section. Question: How good would it be to move this kind of dependency to devDependencies, if only this package needs them? Plus, there are still thoughts in the direction of code duplication, for example, if there is another package that uses the same dependencies and they are also in the bundle. Therefore, another question: Maybe there are some secrets of building npm packages in such a way that their dependencies do not fall into the bundle and, if some other package uses the same ones, there is no duplication? As I understand it, peerDependencies is a bit about something else. Can someone explain the dependencies and their correct use when creating an npm package? in case some other package uses the same ones, there was no duplication? As I understand it, peerDependencies is a bit about something else. Can someone explain the dependencies and their correct use when creating an npm package? in case some other package uses the same ones, there was no duplication? As I understand it, peerDependencies is a bit about something else. Can someone explain the dependencies and their correct use when creating an npm package?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-05-20
@XSpecter

It's good practice not to drag dependencies into a bundle.
webpack has externals
rollup has externals
If you sew your dependencies into your bundle bundle - you create duplication of code in the bundle without options if I need the same dependencies as your package and additionally your package

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question