npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xrnjs/react-native-code-push

v0.0.1

Published

React Native plugin for the CodePush service

Readme

React Native 的 CodePush 模块

工作原理

React Native 应用由 JavaScript 文件以及相关的 图片 组成,这些文件会通过 打包器 打包,并作为平台特定的二进制文件(.ipa.apk)的一部分发布。一旦应用发布,更新 JavaScript 代码(如修复 Bug、新功能)或图片资源,就需要重新编译并重新发布整个二进制文件,还要经过应用商店的审核。

CodePush 插件让你可以在用户设备上即时展示产品改进,通过让 JavaScript 和图片资源与 CodePush 服务器上的更新保持同步,从而实现“离线应用体验”+“网页般的快速更新”。此外,为了保证用户始终有可用版本,CodePush 会保留上一次的更新,以便在你发布了导致崩溃的更新时自动回滚。

注意:涉及原生代码的更改(例如修改 AppDelegate.m/MainActivity.java、添加新插件)不能通过 CodePush 分发,必须通过应用商店更新。


支持的 React Native 平台

  • iOS (7+)
  • Android (4.1+)
  • Windows (UWP)

不同版本的 React Native 对应 CodePush 插件版本,请参考文档中的表格确认兼容性。


支持的组件

当你使用 React Native 的资源系统(require("./foo.png"))时,下列核心组件和属性的图片资源可以通过 CodePush 更新:

| 组件 | 属性 | |------|------| | Image | source | | MapView.Marker (需要 react-native-maps >=0.3.2) | image | | ProgressViewIOS | progressImage, trackImage | | TabBarIOS.Item | icon, selectedIcon | | ToolbarAndroid (React Native 0.21.0+) | actions[].icon, logo, overflowIcon |

不支持动态更新的组件示例(依赖静态 { uri: "foo" }):

| 组件 | 属性 | |------|------| | SliderIOS | maximumTrackImage, minimumTrackImage, thumbImage, trackImage | | Video | source |


快速开始

在完成 CodePush 账号注册与初始化 后,在项目根目录运行:

npm install --save react-native-code-push

根据目标平台(iOS、Android、Windows)执行相应的安装步骤。
如果同时支持多个平台,建议为每个平台创建独立的 CodePush 应用。

详细安装步骤:


插件用法

集成 CodePush 后,需要控制两个策略:

  1. 何时检查更新(如应用启动时、点击按钮时、定时器等)。
  2. 当有更新时,如何呈现给用户。

可以通过将应用根组件 “CodePush 化” 来实现。

方式 1:使用高阶组件:

import codePush from "react-native-code-push";

class MyApp extends Component {}

MyApp = codePush(MyApp);

方式 2:使用 ES7 装饰器语法:

import codePush from "react-native-code-push";

@codePush
class MyApp extends Component {}

默认情况下,CodePush 会在每次应用启动时检查更新,并在下次重启时安装(除非是强制更新,会立即安装)。
你也可以设置在应用从后台恢复时检查更新,或者手动调用 codePush.sync()


应用商店指南合规性

  • Google Play 无限制。
  • iOS App Store 允许 OTA 更新 JS 和资源,但不能改变应用的主要用途、绕过安全机制等。
  • 建议 iOS 不要开启 updateDialog 以避免被认为强制用户操作。

发布更新

使用 CodePush CLI 的 release-react 命令快速发布更新:

code-push release-react MyApp-iOS ios
code-push release-react MyApp-Android android

支持参数如:

  • -m 强制更新
  • --description 更新描述
  • --rollout 分批发布
  • --targetBinaryVersion 目标版本匹配

CodePush 支持差分更新,用户只会下载变更文件。


多部署测试

利用 Staging(预发布)和 Production(生产)环境先测试再发布,避免直接影响所有用户。
可以:

  1. 先发到 Staging
  2. 自己测试
  3. Promote 到 Production

动态部署分配

可以在运行时为特定用户指定不同的部署 key,从而实现:

  • A/B 测试
  • 提前体验版

通过 codePush.sync({ deploymentKey: ... }) 实现。


API 参考


示例应用 / 启动模板

社区的一些开源项目示例:

启动模板:


调试 / 故障排查

  • 使用 code-push debug ioscode-push debug android 查看日志。
  • 确认部署 key 正确、版本匹配。
  • 确认不是 Debug 模式(Debug 模式会直接加载打包器的 JS)。
  • 针对 iOS Release 模式,需要在 AppDelegate.m 中引入 RCTLog.h 并调用 RCTSetLogThreshold(RCTLogLevelInfo)

持续集成 / 发布

可以将 CodePush 集成到 CI/CD 流程中,例如:

  • Visual Studio Team Services
  • Travis CI

TypeScript 使用

本模块自带 *.d.ts 类型定义文件,支持 VS Code 智能提示与编译时检查。
如果在 tsconfig.json 中使用 es6 作为 targetmodule,需将 moduleResolution 设置为 node


本项目遵循 Microsoft 开源行为准则。如有问题可联系 [email protected]