Skip to main content

树外平台

React Native 不仅适用于 Android 和 iOS 设备 - 我们的合作伙伴和社区维护着将 React Native 引入其他平台的项目,例如:

¥React Native is not only for Android and iOS devices - our partners and the community maintain projects that bring React Native to other platforms, such as:

来自合作伙伴

¥From Partners

来自社区

¥From Community

创建你自己的 React Native 平台

¥Creating your own React Native platform

目前,从头开始创建 React Native 平台的过程还没有很好的记录 - 即将到来的重新架构 (Fabric) 的目标之一是使平台维护变得更加容易。

¥Right now the process of creating a React Native platform from scratch is not very well documented - one of the goals of the upcoming re-architecture (Fabric) is to make maintaining a platform easier.

打包

¥Bundling

从 React Native 0.57 开始,你现在可以使用 React Native 的 JavaScript 打包程序 Metro 注册你的 React Native 平台。这意味着你可以将 --platform example 传递给 npx react-native bundle,它将查找带有 .example.js 后缀的 JavaScript 文件。

¥As of React Native 0.57 you can now register your React Native platform with React Native's JavaScript bundler, Metro. This means you can pass --platform example to npx react-native bundle, and it will look for JavaScript files with the .example.js suffix.

要向 RNPM 注册你的平台,你的模块名称必须与以下模式之一匹配:

¥To register your platform with RNPM, your module's name must match one of these patterns:

  • react-native-example - 它将搜索所有以 react-native- 开头的顶层模块

    ¥react-native-example - It will search all top-level modules that start with react-native-

  • @org/react-native-example - 它将在任何范围内搜索以 react-native- 开头的模块

    ¥@org/react-native-example - It will search for modules that start with react-native- under any scope

  • @react-native-example/module - 它将搜索名称以 @react-native- 开头的范围内的所有模块

    ¥@react-native-example/module - It will search in all modules under scopes with names starting with @react-native-

你的 package.json 中还必须有一个条目,如下所示:

¥You must also have an entry in your package.json like this:

{
"rnpm": {
"haste": {
"providesModuleNodeModules": ["react-native-example"],
"platforms": ["example"]
}
}
}

"providesModuleNodeModules" 是将添加到 Haste 模块搜索路径的模块数组,"platforms" 是将添加为有效平台的平台后缀数组。

¥"providesModuleNodeModules" is an array of modules that will get added to the Haste module search path, and "platforms" is an array of platform suffixes that will be added as valid platforms.