React需要rnpm链接的本地组件依赖

我刚刚为React-Native创build了一个组件,我将尽快将它作为一个包加载到npm中。 虽然我面临一个问题。

该组件依赖于另一个名为react-native-image-resizer npm软件包。 这个软件包需要与rnpm连接才能工作。

虽然,当我只是将我的组件安装在一个全新的项目中时,依赖关系将不会自动链接,并且本地库不会出现在项目中。 当然,当我运行rnpm link ,也不会将其添加到项目中。

所以我想知道什么是最好的方式来安装和链接此依赖?

 MacBook-Pro:Example $ npm install react-native-image-crop > react-native-image-crop@1.0.0 preinstall /Users/alexmngn/Work/react-native-image-crop/Example/node_modules/.staging/react-native-image-crop-95365d1b > npm install --save react-native-image-resizer react-native-image-crop@1.0.0 (git+ssh://git@github.com/alexmngn/react-native-image-crop.git#90e002c7d0f01c9d61277c30cad375560f09a94a) /Users/alexmngn/Work/react-native-image-crop/Example/node_modules/.staging/react-native-image-crop-95365d1b ├── UNMET DEPENDENCY react-native@^0.31.0 └── react-native-image-resizer@0.0.9 npm WARN react-native-image-resizer@0.0.9 requires a peer of react-native@>=v0.14.2 but none was installed. npm WARN react-native-image-crop@1.0.0 No repository field. - react-native-image-resizer@0.0.9 node_modules/react-native-image-crop/node_modules/react-native-image-resizer Example@0.0.1 /Users/alexmngn/Work/react-native-image-crop/Example └── react-native-image-crop@1.0.0 (git+ssh://git@github.com/alexmngn/react-native-image-crop.git#90e002c7d0f01c9d61277c30cad375560f09a94a) MacBook-Pro:Example $ rnpm link MacBook-Pro:Example $ # Nothing gets linked here... 

另外,正如你可以看到的那样,当我在我的示例项目中安装我的组件时,即使它在我的package.json的依赖项中正确列出(使用正确的版本),我也有一个与react-native一样的未满足的依赖关系问题:

 { "name": "Example", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start" }, "dependencies": { "react": "15.2.1", "react-native": "^0.31.0", "react-native-image-crop": "git+ssh://github.com/alexmngn/react-native-image-crop.git" } } 

任何想法为什么抱怨?

可在此处获得的组件的回收: http : //github.com/alexmngn/react-native-image-crop.git

谢谢

rnpm link仅链接它在package.jsonfind的package.json ,通常这些包是通过命令rnpm installnpm install --save

为了让那些安装你的软件包的人自动完成这个工作,你可以编写一个preinstall npm脚本,这个脚本将在安装软件包之前执行。

package.json添加这样的scripts

 { "scripts": { "preinstall": "npm install --save react-native-image-resizer@0.0.9" } } 

这样做后,当有人尝试通过npm安装你的pacakge时,首先安装react-native-image-resizer ,同时在package.json – > dependency中添加leave ab条目,这样rnpm链接就可以正常工作。

阅读更多关于npm脚本的信息