1

We all know, in most of the cases, packages listed under devDependencies won't make it into your build. So why do we strip them away in the name of performance?

E.g. I see many posts on Moment.js being replaced with another lightweight alternative, even if Moment.js is in devDependencies. How does it impact, considering all the frameworks (Ember, React, Vue and Angular)?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sarath Damaraju
  • 309
  • 2
  • 13
  • Are you asking about removing unused dependencies? How bundling and tree shaking works? Why people choose to not use Moment.js? If you're trying to reduce your own bundle size, have you observed any impact of these changes on your outputs? – jonrsharpe Dec 20 '19 at 09:14
  • Does this answer your question? [What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?](https://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies) – mbojko Dec 20 '19 at 09:35
  • No, my question is -- why people replace devDependencies in `package.json` in the name of performance?. This is not about unused, or bundling or any mechanisms. I want to get the reason behind the decisions. unused packages should be removed, but am not asking about that – Sarath Damaraju Dec 20 '19 at 11:50

2 Answers2

0

devDependencies do not exclude the possibility that the dependency is required to make a bundle during build time --they are within the bundle that webpack generates for a website-- but not required by the package/system that installs it for production: i.e. the server-package that installs the app-package.

For example: your package app builds moment.js into its distribution bundle. When you then install package app as a dependency in a separate server, it does not need to install moment.js, because it is already bundled within the app's dist - so you explicitly put moment.js as a devDependency in app's package.

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
0

Performance is a broad term. To some people, performance is only about production code. To others, performance of the build system matters. Removing unused devDependencies reduces build time and space, since npm needs to do less work.

rustyx
  • 80,671
  • 25
  • 200
  • 267