For AI agents: the complete documentation index is available at https://rsbuild.rs/zh/llms.txt, the full documentation bundle is available at https://rsbuild.rs/zh/llms-full.txt, and this page is available as Markdown at https://rsbuild.rs/zh/guide/framework/react-lynx.md.
close
  • 简体中文
  • ReactLynx

    在本文档中,你可以了解如何使用 Rsbuild 构建 Lynx 的 ReactLynx 应用。

    创建 ReactLynx 应用

    使用 @lynx-js/create-lynx 创建 ReactLynx 应用:

    npm
    yarn
    pnpm
    bun
    npm create @lynx-js/lynx@latest

    然后在提示 "Select build tool" 时选择 Rsbuild。

    在已有项目中使用 ReactLynx

    编译 ReactLynx 需要注册 Lynx 提供的 ReactLynx 插件,插件会自动添加 ReactLynx 构建所需的配置。

    安装 @lynx-js/react 和插件:

    npm
    yarn
    pnpm
    bun
    deno
    npm add @lynx-js/react
    npm
    yarn
    pnpm
    bun
    deno
    npm add @lynx-js/react-rsbuild-plugin -D

    然后在 Rsbuild 配置文件中注册插件,并将 environment 命名为 lynx,使其被构建为 Lynx bundle:

    rsbuild.config.ts
    import { defineConfig } from '@rsbuild/core';
    import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
    
    export default defineConfig({
      environments: {
        lynx: {},
      },
      plugins: [pluginReactLynx()],
    });

    更多用法请参考 ReactLynx 文档。