简体   繁体   English

我可以为 React Native macOS 应用程序和 React Native Windows 应用程序使用相同的代码库吗?

[英]Can I use the same codebase for both a React Native macOS app and a React Native Windows app?

I am trying to create an app using React Native that runs on iOS, Android, macOS and Windows.我正在尝试使用在 iOS、Android、macOS 和 Windows 上运行的 React Native 创建一个应用程序。 An advantage of being able to use React Native is that you can share code between platforms.能够使用 React Native 的一个优势是您可以在平台之间共享代码。

I am following the setup guides for React Native macOS and Windows , but in the guides, they guide you through creating a new app from scratch for each platform.我正在遵循 React Native macOSWindows的设置指南,但在指南中,它们指导您从头开始为每个平台创建一个新应用程序。 As I want to use the same app, so I don't have to write the same code twice, I create the macOS app following the guide.因为我想使用同一个应用程序,所以我不必两次编写相同的代码,所以我按照指南创建了 macOS 应用程序。 Then, in this app, I use the command npx react-native-windows-init --overwrite from the Windows guide to initialise the Windows platform.然后,在这个应用程序中,我使用 Windows 指南中的命令npx react-native-windows-init --overwrite来初始化 Windows 平台。 But when I then go to run the macOS app using the command npx react-native run-macos , I get the error:但是,当我使用命令npx react-native run-macos去运行 macOS 应用程序时,出现错误:

Cannot find module 'metro-config/src/defaults/exclusionList'找不到模块“metro-config/src/defaults/exclusionList”

and

no bundle URL present 不存在捆绑 URL

One thing I find strange about the setup guides is that for macOS it tells you to use React Native 0.63 and for Windows 0.66.我对安装指南感到奇怪的一件事是,对于 macOS,它告诉您使用 React Native 0.63 和 Windows 0.66。 I used 0.66 for both, maybe this is the problem.我对两者都使用了 0.66,也许这就是问题所在。 But if it is, and each platform requires different versions of React Native, how can I use the one app / codebase for both platforms?但如果是这样,并且每个平台都需要不同版本的 React Native,我该如何为两个平台使用同一个应用程序/代码库? This goes against one of React Native's core premises:这违背了 React Native 的核心前提之一:

Create platform-specific versions of components so a single codebase can share code across platforms.创建特定于平台的组件版本,以便单个代码库可以跨平台共享代码。

Is it possible to create a single app for both desktop platforms like you would with iOS and Android, and if so, how?是否可以像使用 iOS 和 Android 一样为两个桌面平台创建单个应用程序,如果可以,如何创建?


Yes, you can.是的你可以。 You will have to create a mono repo Or you can use mono repo boilerplate.您将必须创建一个 mono 回购或者您可以使用 mono 回购样板。 Here is a link to it https://github.com/mmazzarolo/react-native-universal-monorepo这是它的链接https://github.com/mmazzarolo/react-native-universal-monorepo

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

相关问题 我可以将Web应用程序的组件与React Native应用程序一起使用 - Can I use components of a web app with a React Native app 我如何在反应本机中捕获屏幕截图而不是针对同一个应用程序 - How can I capture screenshot in react native not for the same app 如何在本机中使用共享代码库制作多个应用程序变体? - How to make multiple app variants with shared codebase in react native? 我可以在我的本机应用程序中使用颤振吗? - Can I use flutter in my react native app? 我可以为 React Native 应用程序使用 CSS/样式开发工具吗? - Can I use CSS/style devtools for a React Native app? 我可以在我的 React Native 应用程序中使用这个 Expo 库吗? - Can I use this Expo library in my React Native app? 针对Windows App运行React Native - Running React native for Windows App 如何在React Native中为iOS应用使用和显示与启动图像相同的图像? - How can I use and display the same image shown as Launch Image for an iOS app in React Native? react native - 我应该使用命令 react-native start 运行服务器,以便用户可以使用该应用程序吗? - react native - should I run the server with the command react-native start so that users can use the app? 我可以为Android电视应用程序使用react native吗? - can i use react native for android tv app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM