Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have always placed different "tooling configurations" in their own files in my front-end projects.

For example: babel in babel.config.js, jest in jest.config.js, eslint in an .eslintrc.json, etc.

I have noticed recently however that it is possible to place many of these configurations directly in a projects package.json file instead.

I did some digging around online and asked a few colleagues but no-one can seem to give me a definitive answer as to why one might prefer one approach over the other.

Is it purely a matter of preference?

like image 853
Andrew Hill Avatar asked Dec 10 '19 09:12

Andrew Hill


People also ask

What is the use of config json?

Data from config. json is used to configure virtual machine. After editing file make sure that your JSON syntax is valid. JSONLint can help to check it.

Why we use config in Node JS?

Node-config allows you to create configuration files in your Node application for different deployment environments. With it, you can define a default configuration file that you intend to repeat across environments, then extend the default config to other environments, such as development, staging, etc.

Can I add custom properties to package json?

Yes, you're allowed to add custom entries to package. json .

What does package json do in angular?

This package. json is used by all projects in the workspace, including the initial application project that is created by the CLI when it creates the workspace. Initially, this package. json includes a starter set of packages, some of which are required by Angular and others that support common application scenarios.


1 Answers

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.

like image 132
Z. Zlatev Avatar answered Nov 03 '22 01:11

Z. Zlatev