@elastic/eui-docusaurus-theme

中文文档
2.9.0发布于 2026/11/17SEE LICENSE IN LICENSE.txtTypeScriptCommonJS构建来源已验证近 30 天下载 4914

EUI theme for Docusaurus

原始使用文档
文档目录13 节
  1. Usage
  2. Prerequisites
  3. Installing the preset (recommended)
  4. Theme only
  5. Features
  6. Right-side nav links
  7. Local development
  8. Prerequisites
  9. Installing dependencies
  10. Building the package
  11. Building in watch mode
  12. Test with EUI documentation website
  13. Test locally with your own Docusaurus project

@elastic/eui-docusaurus-theme

EUI custom Docusaurus theme made for the EUI documentation website.

Usage

The EUI theme uses the Swizzling technique to swap the theme component with custom implementation that includes EUI components and tokens.

Prerequisites

Before you get started with installing the preset, update your Docusaurus setup to be compatible with @elastic/eui-docusaurus-theme:

  1. Install required packages

    yarn add @emotion/react @emotion/css @elastic/charts
    
  2. Configure TypeScript

    You need to add jsxImportSource and moduleResolution to your project's tsconfig.json:

    {
        // This file is not used in compilation. It is here just for a nice editor experience.
        "extends": "@docusaurus/tsconfig",
        "compilerOptions": {
            "baseUrl": ".",
    +        "jsxImportSource": "@emotion/react",
    +        "moduleResolution": "nodenext"
        }
    }
    
  3. Configure Babel

    Add @babel/preset-react to allow Emotion to handle importSource.

    module.exports = {
        presets: [
            require.resolve('@docusaurus/core/lib/babel/preset'),
    +       [
    +            '@babel/preset-react',
    +            { runtime: 'automatic', importSource: '@emotion/react' },
    +       ],
        ],
    };
    
# npm
npm install @elastic/eui-docusaurus-preset @elastic/eui-docusaurus-theme

# pnpm
pnpm add @elastic/eui-docusaurus-preset @elastic/eui-docusaurus-theme

# Yarn
yarn add @elastic/eui-docusaurus-preset @elastic/eui-docusaurus-theme

and in your docusaurus.config.ts file, add:

const config: Config = {
    // ...
    presets: [
        require.resolve('@elastic/eui-docusaurus-preset'),
        // ...
    ],
    // ...
}

Theme only

Docusaurus uses Infima, its default CSS framework, to style the classic theme (@docusaurus/theme-classic). The EUI Docusaurus theme is based on the classic theme, but Infima's global styles often override or conflict with EUI's design system, leading to inconsistent appearance. The ignore-styles-plugin disables Infima's styles, ensuring the EUI theme displays correctly. For this reason, we highly recommend using the preset rather than the standalone theme.

If you prefer to use only the theme, install the package:

# npm
npm install @elastic/eui-docusaurus-theme

# pnpm
pnpm add @elastic/eui-docusaurus-theme

# Yarn
yarn add @elastic/eui-docusaurus-theme

and in your docusaurus.config.ts file, add:

const config: Config = {
    // ...
    themes: [
        require.resolve('@docusaurus/theme-classic'), // Required for compatibility
        require.resolve('@elastic/eui-docusaurus-theme'),
    ],
    // ...
}

Features

To achieve similar right-side nav links as on the EUI docs, you have to use the component property that has a value of "changelog" | "github" | "figma".

themeConfig: {
    // ...
    navbar: {
      // ...
      items: [
        // ...
        // Use component: "changelog" | "github" | "figma"
        {
          href: "https://github.com/elastic/eui/tree/main/packages/eui/changelogs",
          label: "EUI Changelog",
          position: "right",
          component: "changelog",
        },
        {
          href: "https://github.com/elastic/eui",
          label: "GitHub",
          position: "right",
          component: "github",
        },
        {
          href: "https://www.figma.com/community/file/964536385682658129",
          label: "Figma",
          position: "right",
          component: "figma",
        },
      ],
    },
    // ...
}

Local development

Prerequisites

This package requires:

Installing dependencies

Install dependencies by running:

yarn

Building the package

yarn build

Building in watch mode

Run the following command to build this package whenever a file is edited:

yarn start

:::warning Please note that this package is configured to do incremental builds and sometimes tsc may not update the lib directory with your latest changes if you rename or delete files.

If that's the case please run yarn build. :::

Test with EUI documentation website

Run the following command from the root of the mono-repository to run the website:

yarn workspace @elastic/eui-website start

You can pair it with the watch mode when modifying the Docusaurus theme.

Test locally with your own Docusaurus project

You should have a Docusaurus project running. If you want to test EUI theme with a fresh project, you should create a Docusaurus scaffolded project website.

Run the following command to create a Docusaurus project:

npx create-docusaurus@latest my-website classic --typescript

In the root, run the following commands to build and pack the preset and theme locally:

# Build packages
yarn workspace @elastic/eui-docusaurus-theme build
yarn workspace @elastic/eui-docusaurus-preset build

# Pack packages
cd packages/docusaurus-theme
yarn pack --filename docusaurus-theme.tgz

cd ../docusaurus-preset
yarn pack --filename docusaurus-preset.tgz

In your project, install EUI dependencies:

# npm
npm install @elastic/eui @elastic/charts @emotion/react @emotion/css moment

# pnpm
pnpm add @elastic/eui @elastic/charts @emotion/react @emotion/css moment

# Yarn
yarn add @elastic/eui @elastic/charts @emotion/react @emotion/css moment

and add the locally packed packages:

# npm
npm install /path/to/eui/packages/docusaurus-preset/docusaurus-preset.tgz /path/to/eui/packages/docusaurus-theme/docusaurus-theme.tgz

# pnpm
pnpm add /path/to/eui/packages/docusaurus-preset/docusaurus-preset.tgz /path/to/eui/packages/docusaurus-theme/docusaurus-theme.tgz

# Yarn
yarn add /path/to/eui/packages/docusaurus-preset/docusaurus-preset.tgz /path/to/eui/packages/docusaurus-theme/docusaurus-theme.tgz

Configure Docusaurus to use the locally built preset as outlined in the Usage section.

Making changes

When you make changes to the preset or theme, rebuild and repack the packages.

Then reinstall the packages in your project to update the changes.

Restart your Docusaurus development server:

# npm
npm run start

# pnpm
pnpm start

# Yarn
yarn start

版本与发布记录

@elastic/eui-docusaurus-theme 共发布 159 个版本,首次发布于 2025/11/18;过去 12 个月发布了 159 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.9.0latest2026/11/17今天
2.8.1-snapshot.1794825855066snapshot2026/11/16今天
2.8.1-snapshot.17945406011672026/11/133 天前
2.8.1-snapshot.17944866778742026/11/124 天前
2.8.1-snapshot.17944540618012026/11/124 天前
2.8.1-snapshot.17943676766812026/11/115 天前

关于 @elastic/eui-docusaurus-theme 的常见问题

@elastic/eui-docusaurus-theme 是什么?

EUI theme for Docusaurus

如何安装 @elastic/eui-docusaurus-theme?

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

@elastic/eui-docusaurus-theme 支持 TypeScript 吗?

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

@elastic/eui-docusaurus-theme 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elastic/eui-docusaurus-theme 可以商用吗?

@elastic/eui-docusaurus-theme 使用 SEE LICENSE IN LICENSE.txt 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@elastic/eui-docusaurus-theme 的下载量有多少?

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

@elastic/eui-docusaurus-theme 还在维护吗?

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