【发布时间】:2020-01-13 22:20:14
【问题描述】:
所以这个问题是对我之前的问题的跟进: How can different apps import from a shared components folder? react / react-native
所以我创建了自己的 npm 模块,我在其中存储了所有组件。这些组件可以被任意数量的应用程序使用。因为我将使这些组件高度可重用。
但我还是偶然发现了一个问题。
我创建了一个使用这个库的加载组件:@react-native-community/masked-view。该库需要在 /ios/Podfile 中安装依赖项。 首先我在其中一个 react-native 项目中创建了这个组件。
yarn add @react-native-community/masked-view
..
success Saved 1 new dependency.
cd ios/
pod install
..
Installing RNCMaskedView (0.1.6)
Pod installation complete! There are 33 dependencies from the Podfile and 31 total pods installed.
'
然后我运行了我的代码,加载组件就可以工作了。现在我想将它添加到 NPM 模块(同样,我自己创建的),它将包含我的所有组件。
所以我进入 /my-awesome-99-components/,它有自己的 package.json,因为它是一个模块,我将在我正在处理的每个项目中导入它。
在 /my-awesome-99-components/
yarn add react react-native @react-native-community/masked-view
..
success Saved 1 new dependency.
// Created Loading.js - this is the loading component
yarn publish
..
在 /react-native-project-1/
yarn add my-awesome-99-components
..
Done in 3.17s.
cd ios/
Pod install
..
这就是问题出现的地方。现在 Podfile 不会安装 RNCMaskedView 因为显然我的模块没有让项目知道它应该在 ios/Podfile 中安装一些包。
有谁知道为什么会发生这种情况,最好的解决方案是什么?
感谢所有帮助!
【问题讨论】:
标签: javascript reactjs react-native module package