简体   繁体   English

如何使用 Gatsby 和 create-react-app 添加 react-native out-of-tree 平台?

[英]How to add react-native out-of-tree platforms using Gatsby and create-react-app?

We have a large react-native application and want to extend this application into a website and chrome-extension, the website and chrome extension use the same reducers, sagas and some components (using react-native-web) from our mobile application.我们有一个大型 react-native 应用程序,并希望将此应用程序扩展到网站和 chrome 扩展程序中,该网站和 chrome 扩展程序使用与我们的移动应用程序相同的减速器、saga 和一些组件(使用 react-native-web)。 The chrome extension and website are basically a subset of the mobile app. chrome 扩展程序和网站基本上是移动应用程序的一个子集。

The idea was to setup the build system to build these platforms in a single repo eg if we run npm run build-chrome-extension it will build the react extension into a root folder called /extension , which will live in the same directory as the /ios and /android folder, same goes for a /web folder.我们的想法是设置构建系统以在单个 repo 中构建这些平台,例如,如果我们运行npm run build-chrome-extension它会将 react 扩展构建到名为/extension的根文件夹中,该文件夹将与/ios/android文件夹,同样适用于/web文件夹。

To achieve this we will use react-native out-of-tree platforms then use file extensions to serve the correct code, CheckoutScreen.website.js will serve the checkout screen for the website.为了实现这一点,我们将使用react-native out-of-tree 平台,然后使用文件扩展名来提供正确的代码, CheckoutScreen.website.js将为网站提供结账屏幕。

The question is, how do we setup the build system to accomplish this?问题是,我们如何设置构建系统来实现这一点? If we want to use Gatsby to build the website, and create-react-app for the chrome-extension.如果我们想使用 Gatsby 来构建网站,并为 chrome-extension 创建-react-app。

Not sure to answer the question, but you can use https://github.com/slorber/gatsby-plugin-react-native-web不确定回答这个问题,但你可以使用https://github.com/slorber/gatsby-plugin-react-native-web

It uses the Expo-web webpack config (which also works in CRA or Next or homemade webpack), which means your web layer will resolve in priority the .web.js extension.它使用 Expo-webpack 配置(也适用于 CRA 或 Next 或自制的 webpack),这意味着您的 web 层将优先解析 .web.js 扩展名。

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

相关问题 领域和反应错误。 无法在使用 create-react-app 创建的应用程序中解析“react-native” - Realm and React error. Can't resolve 'react-native' in app created with create-react-app 如何使用 create-react-app 命令添加 gzip 以响应应用程序 - How to add gzip to react app with create-react-app command 尝试使用 expo 构建 create-react-app 项目,引发有关 react-native 的错误 - Trying to build a create-react-app project with expo, throws error about react-native 找不到 react-native 和 create-react-app 的命令(Mac OS) - Command not found for react-native and create-react-app(Mac OS) 使用 create-react-app 和 storybook 的依赖树错误 - dependency tree error using create-react-app and storybook 如何在 create-react-app 项目中为 lodash 执行摇树? - How to perform tree shaking for lodash in a create-react-app project? 摇树创建反应应用程序? - Tree shaking create-react-app? 如何使用 create-react-app 部署 React 应用程序 - How to deploy a react app using create-react-app 如何将React Router添加到现有的create-react-app中? - How to add React Router to an existing create-react-app? 使用create-react-app会使变量超出范围 - Using create-react-app throws variables out of scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM