@dwelle/excalidraw

中文文档
0.5.0-88aedd6发布于 2026/11/13MITTypeScriptES Module近 30 天下载 8772

Excalidraw as a React component

原始使用文档
文档目录10 节
  1. Installation
  2. Quick start
  3. Next.js / SSR frameworks
  4. LLM / agent tips
  5. Migrating to @excalidraw/[email protected]
  6. Self-hosting fonts
  7. Demo
  8. Integration
  9. API
  10. Contributing

Excalidraw

Excalidraw is exported as a React component that you can embed directly in your app.

Installation

Install the package together with its React peer dependencies.

npm install react react-dom @excalidraw/excalidraw
# or
yarn add react react-dom @excalidraw/excalidraw

Note: If you want to try unreleased changes, use @excalidraw/excalidraw@next.

Quick start

The minimum working setup has two easy-to-miss requirements:

  1. Import the package CSS:
import "@excalidraw/excalidraw/index.css";
  1. Render Excalidraw inside a container with a non-zero height.
import { Excalidraw } from "@excalidraw/excalidraw";
import "@excalidraw/excalidraw/index.css";

export default function App() {
  return (
    <div style={{ height: "100vh" }}>
      <Excalidraw />
    </div>
  );
}

Excalidraw fills 100% of the width and height of its parent. If the parent has no height, the canvas will not be visible.

Next.js / SSR frameworks

Excalidraw should be rendered on the client. In SSR frameworks such as Next.js, use a client component and load it dynamically with SSR disabled.

// app/components/ExcalidrawClient.tsx
"use client";

import { Excalidraw } from "@excalidraw/excalidraw";
import "@excalidraw/excalidraw/index.css";

export default function ExcalidrawClient() {
  return (
    <div style={{ height: "100vh" }}>
      <Excalidraw />
    </div>
  );
}
// app/page.tsx
import dynamic from "next/dynamic";

const ExcalidrawClient = dynamic(
  () => import("./components/ExcalidrawClient"),
  { ssr: false },
);

export default function Page() {
  return <ExcalidrawClient />;
}

See the local examples for complete setups:

LLM / agent tips

If an LLM or coding agent is setting up Excalidraw, these shortcuts usually save more time than re-prompting:

  • Start with a plain <Excalidraw /> in a 100vh container. Add refs, initialData, persistence, or custom UI only after the base embed works.
  • If the canvas is blank, check the CSS import and parent height first. Those are the two most common integration failures.
  • In Next.js or other SSR frameworks, assume client-only rendering first. Use "use client" and dynamic(..., { ssr: false }) before debugging hydration or window is not defined errors.
  • If imports or entrypoints are unclear, inspect node_modules/@excalidraw/excalidraw/package.json. The installed package exports are the source of truth.
  • Do not set window.EXCALIDRAW_ASSET_PATH unless you are intentionally self-hosting fonts/assets.
  • When docs and generated code drift, copy the nearest working example from this repo, especially examples/with-nextjs or examples/with-script-in-browser.

Migrating to @excalidraw/[email protected]

Version 0.18.x removes the old types/-prefixed deep import paths. If you were importing types from @excalidraw/excalidraw/types/..., switch to the new type-only subpaths below.

Old pathNew path
@excalidraw/excalidraw/types/data/transform.js@excalidraw/excalidraw/element/transform
@excalidraw/excalidraw/types/data/types.js@excalidraw/excalidraw/data/types
@excalidraw/excalidraw/types/element/types.js@excalidraw/excalidraw/element/types
@excalidraw/excalidraw/types/utility-types.js@excalidraw/excalidraw/common/utility-types
@excalidraw/excalidraw/types/types.js@excalidraw/excalidraw/types

Drop the .js extension. The new package exports map resolves these paths without it.

These deep subpaths are for import type only. Runtime imports should come from the package root, plus @excalidraw/excalidraw/index.css for styles.

For example:

import { exportToSvg } from "@excalidraw/excalidraw";

Self-hosting fonts

By default, Excalidraw downloads the fonts it needs from the CDN.

For self-hosting, copy the contents of node_modules/@excalidraw/excalidraw/dist/prod/fonts into the path where your app serves static assets, for example public/. Then set window.EXCALIDRAW_ASSET_PATH to that same path:

<script>
  window.EXCALIDRAW_ASSET_PATH = "/";
</script>

Demo

Try the CodeSandbox example.

Integration

Read the integration docs.

API

Read the API docs.

Contributing

Read the contributing docs.

版本与发布记录

@dwelle/excalidraw 共发布 587 个版本,首次发布于 2021/07/04;过去 12 个月发布了 116 个版本。

版本发布日期距今
0.5.0-88aedd6latest2026/11/13今天
0.5.0-c0d67332026/11/13今天
0.5.0-52a1f49fc-fontstest2026/11/076 天前
0.5.0-5f8cdc52026/11/058 天前
0.5.0-b2717402026/10/2816 天前
0.5.0-c3ced812026/10/2816 天前

其他发布通道:preview → 0.4.0-0beaa512,esm → 0.4.0-ee486e1d,rc → 0.6.0-rc.3,next → 0.5.0-b80ed8f68,test → 0.5.0-52a1f49fc-fonts。

关于 @dwelle/excalidraw 的常见问题

@dwelle/excalidraw 是什么?

Excalidraw as a React component

如何安装 @dwelle/excalidraw?

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

@dwelle/excalidraw 支持 TypeScript 吗?

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

@dwelle/excalidraw 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dwelle/excalidraw 可以商用吗?

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

@dwelle/excalidraw 的下载量有多少?

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

@dwelle/excalidraw 还在维护吗?

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