简体   繁体   中英

How to distribute dependencies in package.json?

So I'm building a Front End application based on React. There'll be different packages serving as libraries and exporting components. These components will then be imported into the main package and routed according to need.

Now for the package(s) serving as libraries; I'm trying to understand how to distribute the dependencies between dependencies , devDependencies , and peerDependencies in the package.json file.

Should I be putting everything in dev and peer? Or do things like lodash / babel etc. need to be put in dependencies? Any such best practices; or list of dependencies would be helpful

About dependencies and devDependencies

Dependencies

"dependencies": Packages required by your application in production.

In dependencies you put everything that is imported in your application or needed in some way in the final application, eg: react , axios etc.

devDependencies

"devDependencies": Packages that are only needed for local development and testing.

In devDependencies you put only things that are used to build your application, eg. webpack , eslint etc.

peerDependencies

You can read about peerDependencies here

You won't use them unless your project is a library.

Questions:

Should I be putting everything in dev and peer?

No, it's safer to put everything in dependencies if you don't know where to put it.

Or do things like lodash / babel etc. need to be put in dependencies?

No, lodash should be in dependencies , because, you are using it in your website. babel on the other hand is used only in built time, so it should be in devDependencies .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM