发布时我可以用链接包的版本替换 "link:../dir" 吗?
When publishing can I replace "link:../dir" with the version of the package being linked with?
在我的 package.json 我有
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
这在开发期间工作正常,但是当尝试将包发布到 npm 时,"link:../components" 被发布到包中。
有没有办法获取 "link:../components" 并将其替换为所链接文件中 package.json 的版本?
基本上
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
将转换为
"dependencies": {
"components": "1.2.3",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
在发布到 npm 之前。不过,链接的依赖项将保留在本地。
npm link
是一个开发实用程序,用于在发布 npm 包之前对其进行测试。
https://docs.npmjs.com/cli/link
使用您的示例名称,假设您正在开发一个 npm 包 components
。在开发它时,您想在主项目(包的使用者)中对其进行测试。
解决这个问题的方法是,进入你的 components
包目录,然后 运行 npm link
,这将在你的系统中创建一个全局 link 使其可用到其他项目。
所以现在你可以进入你的主项目目录,并且 运行 npm link components
(components
是你的包的名称,不要与目录名称混淆)
这在开发过程中很好,但在您发布包时当然不起作用。
Is there a way to take the "link:../components" and replace it with the version of >the package.json in the file it's being linked with?
- 首先发布
components
包到npm(一个好的
article
这解释了它)
- 在您的主项目目录中,运行
npm unlink
components
。
这将删除全局 link 到 components
项目目录
- 在您的主项目目录中,运行
npm install components
。
这将从 npm 获取 components
。
在我的 package.json 我有
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
这在开发期间工作正常,但是当尝试将包发布到 npm 时,"link:../components" 被发布到包中。
有没有办法获取 "link:../components" 并将其替换为所链接文件中 package.json 的版本?
基本上
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
将转换为
"dependencies": {
"components": "1.2.3",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
在发布到 npm 之前。不过,链接的依赖项将保留在本地。
npm link
是一个开发实用程序,用于在发布 npm 包之前对其进行测试。
https://docs.npmjs.com/cli/link
使用您的示例名称,假设您正在开发一个 npm 包 components
。在开发它时,您想在主项目(包的使用者)中对其进行测试。
解决这个问题的方法是,进入你的 components
包目录,然后 运行 npm link
,这将在你的系统中创建一个全局 link 使其可用到其他项目。
所以现在你可以进入你的主项目目录,并且 运行 npm link components
(components
是你的包的名称,不要与目录名称混淆)
这在开发过程中很好,但在您发布包时当然不起作用。
Is there a way to take the "link:../components" and replace it with the version of >the package.json in the file it's being linked with?
- 首先发布
components
包到npm(一个好的 article 这解释了它) - 在您的主项目目录中,运行
npm unlink components
。
这将删除全局 link 到components
项目目录 - 在您的主项目目录中,运行
npm install components
。
这将从 npm 获取components
。