0

How to minimize the size of our npm package and Do we need to add webpack as dependency when publishing an npm package. I have referred below article: https://medium.com/quick-code/publish-your-own-react-component-as-npm-package-under-5-minutes-8a47f0cb92b9

I have published my first npm package. But when we install it from npm package it says 'added 67 packages'. Why 67 packages?

This is the dependency section from package.json: "dependencies": { "react": "16.8.6", "webpack": "4.32.2", "react-icons": "3.7.0" },

harshit
  • 196
  • 1
  • 8

1 Answers1

1

You have only 3 dependencies in your package.json. But each of these dependencies contains a lot other dependencies inside.

Let's see how many dependencies (including nested) does your package have:

$ npx howfat react@16.8.6 webpack@4.32.2 react-icons@3.7.0
Dependencies: 356
Size: 36.79mb
Files: 3403

Why so many, not just 67? Because the project which includes your package has a lot of other dependencies. 67 is just a number of new packages, which were not included before.

In most cases you should not specify webpack as a dependency. You could install it as a dev dependency instead:

npm install --save-dev webpack

Webpack is a huge package, so it's too expensive to include it as dependency.

Alexey Prokhorov
  • 3,431
  • 1
  • 22
  • 25