gpt4 book ai didi

node.js - react native : is it possible to avoid storing all dependencies in node_modules subfolder

转载 作者:搜寻专家 更新时间:2023-11-01 00:29:51 26 4
gpt4 key购买 nike

我是 ReactNative 的新手,很抱歉,如果它很明显,但是..

每个通过 CLI 初始化的 RN 项目都有大量的 Node 模块存储在 project_root/node_modules 中。不是我会介意,但如果你有几个项目,它似乎是多余的并且占用时间/空间将它移动到源版本控制系统。

难道不能从机器上的通用 node_modules 中检索所有这些相同的模块吗?

最佳答案

您永远不想在源代码管理中存储嵌套在 node_modules 中的依赖项……这通常会破坏版本控制和依赖项的全部目的。您的 package.json 文件将指定版本,因此当您运行 npm install 时,它会确切地知道要获取哪些依赖项。

作为替代方案,Yarn是 Facebook 开发的一个新兴的包客户端,它在本地缓存你的包方面做得更好,这样如果多个项目重用相同的依赖项,它仍然会满足将它们保存在 node_modules 中的需要 但不需要为每个请求执行 http 请求。

Yarn 不会取代 NPM 作为包注册表,只是一个更好的客户端来下载、维护和缓存这些包。

Yarn 还添加了一个 yarn.lock 文件(类似于 Ruby 的 Gemfile.lock),允许您锁定应用程序中使用的特定版本,而不管 package.jsonThis file can be stored in version control ,这可能是您希望通过在版本控制中保存 node_modules 来实现的。

一些不错的读物...

关于node.js - react native : is it possible to avoid storing all dependencies in node_modules subfolder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com