@battlefieldduck/xterm-svelte

中文文档
2.3.0发布于 2026/05/18MITTypeScriptES Module构建来源已验证近 30 天下载 1.1万

A SvelteKit wrapper for Xterm.js, enabling terminal embedding in SvelteKit apps, managing Xterm addons, and providing seamless updates with the latest SvelteKit and Xterm.js versions.

原始使用文档
文档目录10 节
  1. Version Compatibility
  2. Features
  3. Installation
  4. Usage
  5. FAQ
  6. When should I use onLoad() ?
  7. Real-world uses
  8. Contributing
  9. License
  10. Stargazers over time

Xterm Svelte

Node.js Build NPM Type Definitions NPM Version NPM Downloads NPM Downloads NPM License

xterm-svelte is a wrapper for the xterm.js library, designed to work seamlessly with SvelteKit. This library allows you to embed a fully functional terminal in your SvelteKit application.

Check it out: https://xterm-svelte.pages.dev

Version Compatibility

VersionSvelte VersionBranchDemonstration
2.x.xSvelte 5mainhttps://xterm-svelte.pages.dev
1.x.xSvelte 4svelte4https://svelte4.xterm-svelte.pages.dev

For details on migrating from version 1.x.x to 2.x.x, refer to the Migration Guide.

Features

  • Full integration with SvelteKit

    Xterm-Svelte is designed to work seamlessly with SvelteKit, allowing you to easily incorporate terminal functionality into your SvelteKit projects.

  • Xterm addons management

    Xterm addons are managed within Xterm-Svelte, providing a unified and consistent interface for working with Xterm and its addons.

  • Continuous package updates

    Xterm-Svelte is regularly updated to ensure compatibility with the latest versions of SvelteKit and Xterm.js. This means you can always use the latest features and improvements from these libraries in your projects.

Installation

To install Xterm-Svelte, run the following command in your project directory:

npm install @battlefieldduck/xterm-svelte

Usage

Here's a basic example of how to use xterm-svelte in your SvelteKit application:

<script lang="ts">
    import { Xterm, XtermAddon } from '@battlefieldduck/xterm-svelte';
    import type {
        ITerminalOptions,
        ITerminalInitOnlyOptions,
        Terminal
    } from '@battlefieldduck/xterm-svelte';

    let terminal = $state<Terminal>();

    const options: ITerminalOptions & ITerminalInitOnlyOptions = {
        fontFamily: 'Consolas'
    };

    async function onLoad() {
        console.log('Child component has loaded');

        // FitAddon Usage
        const fitAddon = new (await XtermAddon.FitAddon()).FitAddon();
        terminal?.loadAddon(fitAddon);
        fitAddon.fit();

        terminal?.write('Hello World');
    }

    function onData(data: string) {
        console.log('onData()', data);
    }

    function onKey(data: { key: string; domEvent: KeyboardEvent }) {
        console.log('onKey()', data);
    }
</script>

<Xterm bind:terminal {options} {onLoad} {onData} {onKey} />

FAQ

When should I use onLoad()?

The onLoad() function fires when the xterm terminal is first initialized. You can use this function to perform actions such as initializing xterm addons.

Real-world uses

  • Bitor: Bitor Scanning Software
  • Asm editor: A modern webapp to write, run and learn M68K, MIPS, RISC-V, X86 assembly
  • Sylve: Lightweight GUI for managing Bhyve, Jails, ZFS, networking, and more on FreeBSD
  • And much more...

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

https://github.com/BattlefieldDuck/xterm-svelte/graphs/contributors

License

xterm-svelte is licensed under the MIT License. See the LICENSE file for more details.

Stargazers over time

Stargazers over time

版本与发布记录

@battlefieldduck/xterm-svelte 共发布 11 个版本,首次发布于 2024/04/28;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.3.0latest2026/05/185 个月前
2.2.12026/01/199 个月前
2.2.02025/12/2410 个月前
2.1.12025/09/291.1 年前
2.1.02024/11/182 年前
2.0.12024/11/102 年前

关于 @battlefieldduck/xterm-svelte 的常见问题

@battlefieldduck/xterm-svelte 是什么?

A SvelteKit wrapper for Xterm.js, enabling terminal embedding in SvelteKit apps, managing Xterm addons, and providing seamless updates with the latest SvelteKit and Xterm.js versions.

如何安装 @battlefieldduck/xterm-svelte?

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

@battlefieldduck/xterm-svelte 支持 TypeScript 吗?

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

@battlefieldduck/xterm-svelte 支持 ESM 还是 CommonJS?

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

@battlefieldduck/xterm-svelte 可以商用吗?

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

@battlefieldduck/xterm-svelte 的下载量有多少?

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

@battlefieldduck/xterm-svelte 还在维护吗?

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