简体   繁体   English

将目录转换为npm包时如何管理依赖项?

[英]How to manage dependencies when converting a directory into npm package?

A project write in react, with a directory maybe ui-components . 一个用React编写的项目,其目录可能是ui-components

And now I'm trying convert this directory into a npm package. 现在,我正在尝试将此目录转换为npm软件包。

The easy part is that package.json tells where to find components to import, which is write as "main": "./src/index.js" . 最简单的部分是package.json告诉在哪里找到要导入的组件,该组件写为"main": "./src/index.js"

It works perfect, and it can import things from outside node_modules directory since nothing is installed in ui-components/node_modules . 它工作完美,并且可以从node_modules目录外部导入内容,因为ui-components/node_modules未安装任何ui-components/node_modules

But as a package, I'm trying add @storybook/react and maybe other dependencies, some of them are consistent but has different version. 但是作为一个包,我正在尝试添加@storybook/react以及其他依赖项,其中一些是一致的,但是版本不同。

Is there a way I can easily use the outside node_modules as I do now, or is there a way to simply synchronize the version in ui-components/package.json with the outside package.json ? 有没有办法像现在一样轻松使用外部的node_modules ,还是有办法简单地将ui-components/package.json的版本与外部的package.json同步?

I'm not going to install the inside ui-components , but I want to code them together and release the inside one. 我不会安装内部ui-components ,但是我想将它们一起编码并释放内部ui-components

It sounds like you are looking for peerDependencies 听起来您正在寻找peerDependencies

"In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation." “在某些情况下,您想表达软件包与主机工具或库的兼容性,而不必一定要对此主机进行要求。通常将其称为插件。值得注意的是,您的模块可能会公开特定的接口,并由主机文档指定。”

{
  "name": "tea-latte",
  "version": "1.3.5",
  "peerDependencies": {
    "tea": "2.x"
  }
}

It turns out that I'm looking for a package manage tool like lerna or @microsoft/rush . 事实证明,我在寻找lerna@microsoft/rush类的包管理工具。

And in my case, it's a bit different and I may write some build script to deal with these package manage stuff. 就我而言,这有点不同,我可能会编写一些构建脚本来处理这些程序包管理问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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