@cdx-ui/web

中文文档
0.3.12发布于 2026/11/04MITTypeScriptESM + CJS零依赖近 30 天下载 2547

Vite integration for using Forge UI in React web applications.

原始使用文档
文档目录5 节
  1. Installation
  2. Configure Vite ( forge() )
  3. forge() options
  4. Testing with Vitest ( forgeVitest() )
  5. forgeVitest() options

@cdx-ui/web

Vite integration for using Forge UI in React web applications.

Installation

Install @cdx-ui/web at the same version as your other Forge UI packages:

npm install --save-dev @cdx-ui/web vite @tailwindcss/vite tailwindcss uniwind

Configure Vite (forge())

Add forge() before the React plugin and point it at your application's CSS entry file:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { forge } from '@cdx-ui/web/vite';

export default defineConfig({
  plugins: [forge({ cssEntryFile: 'src/index.css' }), react()],
});

forge() configures Tailwind and Uniwind, React Native Web resolution, dependency pre-bundling, and compatibility settings required by Forge UI.

forge() options

OptionTypeDefaultDescription
cssEntryFilestring—Relative path to the application's CSS entry file.
patchWorkletsbooleantrueApplies the React Native Worklets compatibility patch.

Testing with Vitest (forgeVitest())

Do not put forge() in vitest.config.ts. Uniwind's Vite adapter aliases react-native in a way that Vitest resolves to the Flow-syntax native package. Use forgeVitest() instead:

import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import { forgeVitest } from '@cdx-ui/web/vite';

export default defineConfig({
  plugins: [react(), forgeVitest()],
  test: {
    setupFiles: ['./src/__tests__/setup.ts'],
  },
});
// src/__tests__/setup.ts
import '@testing-library/jest-dom/vitest';
import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';

afterEach(() => {
  cleanup();
});

Wrap Forge UI under test in ForgeDesignProvider (Dialog and other overlays need its portal host):

import type { ReactElement } from 'react';
import { render } from '@testing-library/react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { ForgeDesignProvider } from '@cdx-ui/components';

export function renderWithForgeProviders(ui: ReactElement) {
  return render(ui, {
    wrapper: ({ children }) => (
      <SafeAreaProvider>
        <ForgeDesignProvider config={{ toast: false }}>{children}</ForgeDesignProvider>
      </SafeAreaProvider>
    ),
  });
}

forgeVitest() owns:

  • react-native → react-native-web (not Uniwind's Vite alias)
  • @react-native-aria/* → ESM lib/module entries
  • @cdx-ui/* inlining so Bob ESM directory imports resolve
  • jsdom stand-ins for Uniwind, Reanimated, Gesture Handler, Worklets, Safe Area, SVG, Screens, Bottom Sheet, FlashList, Flash Calendar, and Reanimated Carousel

Those stand-ins are import-time boundaries. Tests exercise the real @cdx-ui/components API; they do not validate production CSS, animation timing, or native gestures. See @cdx-ui/web/testing for the mock package list.

A maintained consumer harness lives in examples/forge-ui-mui-vite.

forgeVitest() options

OptionTypeDefaultDescription
optimizerIncludestring[][]Extra Vitest dependency-optimizer include entries

版本与发布记录

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

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

其他发布通道:staging → 0.1.0。

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

@cdx-ui/web 是什么?

Vite integration for using Forge UI in React web applications.

如何安装 @cdx-ui/web?

在项目目录运行 npm install @cdx-ui/web,或使用 pnpm add / yarn add / bun add。

@cdx-ui/web 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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