6

I was playing with create-react-app and found out that it does put all packages under normal "dependencies". I built the app and found out the 'build' folder size was 2.66 MB.

Then I manually moved the packages not needed in production to "devDependencies" and built again, but the 'build' folder size was still 2.66 MB.

Is there some logic in the webpack.prod.js file, that knows what is needed even if all the packages are listed under "dependencies"?

If so, is there still some benefits using "devDependencies" in package.json?

juwss
  • 79
  • 1
  • 7
  • Possible duplicate of [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) – Dawid Karabin Jul 28 '17 at 09:03

1 Answers1

13

When webpack builds your project it determines everything your project depends on, starting at the entry file, and then combines, uglifies and so on, and disregards everything else.

For example, if index.js is your entry file and it depends on moment.js, moment.js will be included in your build regardless if it's a dependency or devDependency.

The reason for this is npm distinguishes between dependencies and devDependencies, while webpack only distinguishes between that which is needed and that which is not.

If so, is there still some benefits using "devDependencies" in package.json?

I still use devDependencies, but solely as a means of ordering my package.json, but everything can safely be in dependencies when a tool such as webpack is used to build the production site/app

Ettienne
  • 336
  • 3
  • 8