What are the benefits of adding configs to package.json?

My suggestion is to avoid stuffing package.json with custom configs mainly for two reasons.

First is regarding developer expectations. Putting yourself in the position of a person that is just getting off with JavaScript and NPM ecosystem, you see something that's not documented, at least not where you expect it to be. This kind of experience could easily drive folks away especially if they come from more strict developer platforms and languages.

Second, keyword collision or more importantly the thought of such being possible. We don't expect NPM to consider not using some keyword in the future just because some shiny new lib is using it too, do we?

On the other hand having dedicated files for babel, browserlist, postcss is such more simple, self-explanatory approach and every single of those projects already recommends using dedicated files for configurations.


Here are the Pros and Cons of package.json configs IMO:

Pro package.json becomes a single source of truth for your apps packages, scripts, and, now, configs. It's a one-stop for everything related to your app.

Pro It declutters your root directory. Having a separate config file floating around for all your different packages gets messy.

Con Keyword collision possibility. If Node comes out with a new keyword that happens to match that of an existing package config, then you have to either not use the keyword or move the config to a separate file.

Con Most package documentation references the separate config file in their examples. It could be confusing for troubleshooting or new team members.

Con Your package.json file could get HUGE. And if many configs are managed, the potential for a merge conflict with another team member increases greatly.

Overall it comes down to personal preference. There are some tools like husky (https://github.com/typicode/husky) that put config in package.json by default. Our team does a combination of both.