[英]How to distribute dependencies in package.json?
So I'm building a Front End application based on React.所以我正在构建一个基于 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.
然后将这些组件导入主package 并根据需要进行布线。
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.我试图了解如何在
package.json
文件中分布dependencies
、 devDependencies
和peerDependencies
之间的依赖关系。
Should I be putting everything in dev and peer?我应该把所有东西都放在 dev 和 peer 中吗? Or do things like lodash / babel etc. need to be put in dependencies?
还是需要将 lodash / babel 等东西放入依赖项中? Any such best practices;
任何此类最佳做法; or list of dependencies would be helpful
或依赖项列表会有所帮助
About dependencies and devDependencies 关于依赖项和 devDependencies
"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.在依赖项中,您将在应用程序中导入或以某种方式需要的所有内容放入最终应用程序中,例如:
react
、 axios
等。
"devDependencies": Packages that are only needed for local development and testing.
“devDependencies”:仅用于本地开发和测试的包。
In devDependencies you put only things that are used to build your application, eg.在 devDependencies 中,您只放置用于构建应用程序的东西,例如。
webpack
, eslint
etc. webpack
, eslint
等
You can read about peerDependencies here您可以在此处阅读有关 peerDependencies 的信息
You won't use them unless your project is a library.除非您的项目是一个库,否则您不会使用它们。
Questions:问题:
Should I be putting everything in dev and peer?
我应该把所有东西都放在 dev 和 peer 中吗?
No, it's safer to put everything in dependencies
if you don't know where to put it.不,如果您不知道将所有内容放在哪里,则将所有内容放在
dependencies
项中会更安全。
Or do things like lodash / babel etc. need to be put in dependencies?
还是需要将 lodash / babel 等东西放入依赖项中?
No, lodash
should be in dependencies
, because, you are using it in your website.不,
lodash
应该在dependencies
中,因为您在您的网站中使用它。 babel
on the other hand is used only in built time, so it should be in devDependencies
.另一方面,
babel
只在构建时使用,所以它应该在devDependencies
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.