For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/integration/rspack/index.md.
close
  • 简体中文
  • Rspack

    Rspack 是基于 Rust 编写的高性能 JavaScript 打包工具,提供与 webpack 兼容的 API,并支持复用 webpack 的 loader 和插件。

    如果你的项目使用 Rspack 构建,可以使用 Rstest 编写和运行测试,并通过适配器复用 Rspack 配置中兼容的编译选项,减少重复配置,让测试编译与项目构建保持一致。

    快速开始

    已有项目可以参考快速开始,完成 Rstest 的安装和测试脚本配置。

    复用 Rspack 配置

    @rstest/adapter-rspack 会读取 Rspack 配置,并将兼容的选项转换到 Rstest test compiler。

    安装适配器

    npm
    yarn
    pnpm
    bun
    deno
    npm add @rstest/adapter-rspack -D

    扩展配置

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    import { withRspackConfig } from '@rstest/adapter-rspack';
    
    export default defineConfig({
      extends: withRspackConfig(),
    });

    适配器会读取 rspack.config.ts,将兼容的 compiler 选项与生成的测试构建合并,并将已加载的配置文件加入 forceRerunTriggers,因此当该配置发生变化时,--changed 会运行完整测试套件。

    Warning

    Rstest 内部使用 Rsbuild,因此适配器会保留 Rstest 自己负责的测试结构,并始终移除内置的 rsbuild:cssrsbuild:lessrsbuild:sass CSS plugin。这样会导致部分 Rsbuild 专属 CSS 选项(例如 output.cssModules)不可用。

    如果默认的 Rspack 配置不适合当前项目,可以使用 cwdconfigPathconfigName 或 environment 相关选项。选项详情、映射规则和调试方法请查看配置参考

    示例项目

    完整的 React 项目示例请查看 Rspack adapter example

    相关文档