学习 React JS,我想构建一个带有导出的 React 组件的 git 存储库,以便在单独的 React 应用程序中作为一个包使用/安装。
我在 git 存储库中实现了一些 UI 组件,并通过 git HTTP 链接安装它。喜欢:
"ui-components": "https://user_name@bitbucket.org/repo_path.git#branch_name"
我一直在更改代码并推送到远程存储库,为了在开发时节省成本,我正在从本地目录安装。喜欢:
"ui-components": "file:../path_to_that_repository"
这样做,我不必将更改推送到远程存储库并可以重新安装它。
现在,我必须通过删除 node_modules/ui-components
的旧副本并从 yarn.lock
中删除条目来重新安装包,然后按路径安装它。
它使它变得完美,但需要太多时间。
我想要一个命令来更新特定包,方法是从提到的源安装它。
尝试了以下但由于提到的原因失败了:
yarn install
[it verify the yarn.lock and Says UPDATED]yarn install
ui-components [it verify the yarn.lock and Says UPDATED]yarn upgrade
[upgrade COMPLETE dependency list]yarn upgrade ui-components
[upgrade COMPLETE dependency list]yarn add ui-components
[starts finding it as a published package onnpm.js
]
最佳答案
根据 npm
文档,您可以提及 commit-id 或 semver 版本(包含在依赖项项目的 package.json 中)以帮助 yarn 或 npm 识别存在可安装的最新版本。
在这里阅读文档:https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
例子:
git+ssh://git@github.com:npm/npm.git#v1.0.27
git+ssh://git@github.com:npm/npm#semver:^5.0
git+https://isaacs@github.com/npm/npm.git
git://github.com/npm/npm.git#v1.0.27
了解您的顾虑后:
假设您的存储库 react-plugin
是您要包含在项目 react-project
中的存储库。
在 react-plugin
的 package.json 中,指定一个版本,比如 1.0.0
下次更新 react-plugin
时,请确保也更新版本。
Yarn/npm 将检测到该版本差异并根据该差异更新您的本地依赖项。
希望这能解决您的问题。
关于javascript - 将 git 存储库重新安装为 React 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48275858/