将 Lerna 与 React Native 一起使用?

Use Lerna with React Native?

是否可以将 Lerna (lernajs.io) 与 React Native 一起使用?我正在尝试创建具有以下结构的新项目:

MyApp
  packages
    myapp-core
    myapp-mobile
    myapp-web

lerna bootstrap 似乎与 coreweb 没有任何问题,但 mobile(这是一个 React Native 项目)拒绝找到 myapp-core模块。

我记得 React Native 中的 npm link 有一些问题。那是导致问题的原因吗?这个功能最终会存在吗?

react-native: 0.40.0 开始,lerna 看起来像预期的那样工作。我创建了一个最小的演示应用程序,它使用 shared 包为感兴趣的人更改 React 和 React Native 应用程序的背景颜色:

https://github.com/samcorcos/learna-react-native

重现步骤:

  1. 克隆存储库并 cd
  2. npm install
  3. ./node_modules/.bin/lerna bootstrap

然后您可以 运行 每个应用程序(npm start 用于 React,react-native run-ios 用于 React Native),您会看到背景根据共享的输入更改为红色回购。添加新包时,请确保将新包添加到每个相关的 package.json 文件中,就像我将 shared 添加到 Web 和移动项目中一样。

请注意,此项目未利用 Lerna 的 --independent 版本控制系统。

是的,可以在本机和网络平台中为 运行 lerna 创建一个带有 React 的工作区。

事实上,当您打算在您的应用程序中共享 JS 逻辑时,在 lerna 风格的 monorepo 中拥有一个网络移动项目可能是一个不错的选择。

创建了以下 monorepo 作为示例:

https://github.com/agrcrobles/react-native-web-workspace

有关更多信息,请查看:

https://blog.hellojs.org/a-cross-platform-app-with-react-in-a-monorepo-9c6aa6aed818

如评论中所述React Native packager is not working with symlinks。这使得无法使用 Lerna 从同一个 monorepo 创建指向本地子包的符号链接。

幸运的是,有一个支持符号链接的替代打包程序。到目前为止对我来说效果很好 https://github.com/callstack-io/haul/