@cdx-ui/native

中文文档
0.3.12发布于 2026/11/04MITTypeScriptESM + CJS近 30 天下载 2332

coverage

原始使用文档
文档目录7 节
  1. No root export — subpaths only
  2. Installation
  3. Fonts — the config plugin
  4. Migrating from useForgeFonts
  5. @cdx-ui/native/metro
  6. Web hosts
  7. Related packages

@cdx-ui/native

coverage

Native (Metro / Expo) platform integration for Forge UI — the Expo config plugin that embeds Forge fonts and the Metro config wrapper. Keeps @cdx-ui/styles and @cdx-ui/components platform-neutral so web hosts never pull Expo or font binaries by accident.

No root export — subpaths only

This package ships no . entry. A bare import '@cdx-ui/native' fails at resolution by design: each subpath owns its own dependency lifecycle, and a root barrel would re-aggregate them into exactly the chokepoint this package exists to remove.

EntryExportsDependency lifecycle
@cdx-ui/native (config plugin)Expo config plugin, via app.plugin.jsBuild-time — expo/config-plugins (optional peer), font files
@cdx-ui/native/metrowithForgeMetroConfig, ForgeMetroConfigOptionsBuild-time — metro-config, uniwind/metro (optional peers)
@cdx-ui/native/fontsuseForgeFonts (deprecated)Runtime — none

Build-time dependencies are declared as optional peers, never root dependencies, so nothing in this package drags a build tool into a runtime install.

The repository's architecture documentation records the full decision under "Platform Integration Packages".

Installation

npm install @cdx-ui/native

Peer dependencies — install what the subpath you use requires. Platform peers below are optional; react is required (^18.2.0 || ^19.0.0).

PeerVersionRequired byOptional
react^18.2.0 || ^19.0.0@cdx-ui/native/fontsno
expo>=52.0.0the config pluginyes
react-native>=0.76.0the config plugin's native codeyes
metro-config>=0.80.0@cdx-ui/native/metroyes
uniwind>=1.0.0@cdx-ui/native/metroyes

Fonts — the config plugin

Add the plugin to your Expo config and rebuild the native app (npx expo prebuild, or any expo run:* / EAS build):

{
  "expo": {
    "plugins": ["@cdx-ui/native"]
  }
}

It embeds every font family the Forge tokens can name — every selectable Display family, and the Android mono family — and registers each one as one family carrying all of its faces, which is what lets font-medium, font-semibold, font-bold and italic select a real face:

  • iOS — the face files are bundled and listed in UIAppFonts. iOS groups them by the family name inside each file, so React Native picks the face from fontFamily, fontWeight and fontStyle.
  • Android — each family becomes an XML font family registered with React Native's font manager, the only path on which React Native applies numeric weights and italic to a custom font. The system Roboto family is registered the same way, so font-medium and font-semibold reach real system weights instead of collapsing onto regular.

The body and mono families on iOS are the system fonts, which need no embedding. Fonts are selected by the CSS variable layer in @cdx-ui/styles, including a ThemeOverride that switches the Display family at runtime — the plugin has no FI config awareness.

The plugin needs a development build; Expo Go cannot load config plugins. It writes its Android registration in its own MainApplication block, so it coexists with an expo-font plugin entry configured for an app's own fonts.

Web is unaffected. Browser apps register fonts with @cdx-ui/styles/fonts and should not install this package.

Migrating from useForgeFonts

useForgeFonts loaded fonts at runtime through expo-font, which registers each face as a separate family — a shape that cannot carry weight or italic on Android. It is now deprecated and always reports { loaded: true, error: null }. Add the plugin, rebuild, and remove the hook and any rendering gate on loaded.

@cdx-ui/native/metro

withForgeMetroConfig wraps a Metro config with Forge UI's styling-layer configuration. It must be the outermost wrapper if you compose multiple Metro config wrappers.

const { getDefaultConfig } = require('expo/metro-config');
const { withForgeMetroConfig } = require('@cdx-ui/native/metro');

const config = getDefaultConfig(__dirname);

module.exports = withForgeMetroConfig(config, {
  cssEntryFile: './global.css',
  generatedTypesFile: './uniwind-types.d.ts',
});
OptionTypePurpose
cssEntryFilestringPath to the CSS entry file (e.g. './global.css').
generatedTypesFilestringOptional path for generated Tailwind class type definitions.

Today this delegates to Uniwind. If the styling layer is swapped, only the internals of this function change — consuming Metro configs stay the same.

Web hosts

Expo web bundles through Metro, so an Expo-web build imports @cdx-ui/native/metro. That is an accepted consequence of the platform axis. Non-Expo web hosts (Vite, Next.js) need neither subpath: they must load fonts through their own web font path (@font-face rules or a web font provider) and configure Tailwind directly.

PackageOwns
@cdx-ui/stylesDesign tokens, CSS artifacts, theming utilities (platform-neutral)
@cdx-ui/componentsStyled cross-platform components (platform-neutral)

版本与发布记录

@cdx-ui/native 共发布 63 个版本,首次发布于 2026/08/19;过去 12 个月发布了 63 个版本。

版本发布日期距今
0.3.12latest2026/11/045 天前
0.3.112026/10/3010 天前
0.3.102026/10/3010 天前
0.3.92026/10/3010 天前
0.3.82026/10/2812 天前
0.3.72026/10/2713 天前

其他发布通道:staging → 0.1.0。

关于 @cdx-ui/native 的常见问题

如何安装 @cdx-ui/native?

在项目目录运行 npm install @cdx-ui/native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.2.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cdx-ui/native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cdx-ui/native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cdx-ui/native 可以商用吗?

@cdx-ui/native 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cdx-ui/native 的下载量有多少?

根据 npm 官方下载统计,@cdx-ui/native 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,332 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cdx-ui/native 还在维护吗?

最新版本 0.3.12 发布于 2026/11/04(5 天前);至今共发布 63 个版本,其中过去 12 个月发布了 63 个;首次发布于 2026/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。