# @frangio/servbot 中文文档

规范地址：https://npmcn.com/package/%40frangio/servbot/

版本：0\.3\.0-1
npm 元数据更新时间：2025-06-05T17:55:50.006Z
中文译文更新时间：2026-11-15T12:57:42.315Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40frangio/servbot
原文对照：https://npmcn.com/package/%40frangio/servbot/?lang=original
项目主页：https://github.com/kevinfiol/servbot#readme
源码仓库：https://github.com/kevinfiol/servbot

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：35.2 kB，6 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=12\.x
- 运行依赖：0 个
- 首次发布：2022-09-17T18:33:33.890Z
- 最新版本发布：2025-06-05T17:55:49.844Z
- 近 30 天下载量：7000（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

一个用于本地静态站点开发的小型 Dev 服务器脚本

## 安装

```sh
npm install @frangio/servbot
```

也可以使用：`pnpm add @frangio/servbot`、`yarn add @frangio/servbot`、`bun add @frangio/servbot`

## README

# 服务器

一个用于本地静态站点开发的小型dev服务器. 基本上是一个包裹周围 [页:1 服务器](https://nodejs.org/api/http.html#class-httpserver). 叉线 [服务器](https://github.com/lukejacksonn/servor)。 。 。 .

```js
import servbot from 'servbot';

const server = servbot({
    root: './public/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);
```

这是一个有观点的叉子,有一些有意排除和范围较小,一些想法取自: [本地w/服务器](https://github.com/nativew/serve)。 。 。 .

## 安装

```bash
npm install servbot --save-dev
```

## 使用量

参见类型 [指数.d.ts](https://npmcn.com/index.d.ts). servbot接受一个单一的论据, `ServbotOptions`;并返回实例 `ServbotServer`。关于默认选项,见下文.

```js
import servbot from 'servbot';

const server = servbot({
    // root: string
    // Directory to serve. Relative to process.cwd().
    root: '.',

    // reload: boolean
    // Flag to enable manual reload.
    reload: false,

    // fallback: string
    // Filename to fallback to for single-page applications. Relative to `root`.
    // Leaving this empty assumes you are not serving a single-page application
    fallback: '',

    // ignores: RegExp[]
    // *Only applicable when `fallback` is provided and `ignores` is not an empty array*.
    // A list of patterns to *not* route to your fallback.
    // Useful when you want to be able to route non-filetypes to your SPA ("/foo/routename.hi")
    // But otherwise, want to "ignore" routes that should be static files ("/main.css", "/js/jquery.js")
    ignores: [],

    // credentials: object
    // TLS Credentials. Providing these enables an HTTPS server.
    // See https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener
    credentials: undefined,

    // verbose: boolean
    // Flag to enable server response logging.
    verbose: true
});

// Start server on port 8080
server.listen(8080);

// Close server from new connections
// https://nodejs.org/api/net.html#serverclosecallback
server.close((err) => {
    if (err) process.exit();
});
```

### 使用手动重装

Servbot 不包含一个文件监视器,以便在文件更改时自动重新加载您的应用程序,而是包含一个 _手动_ 重新装入特性 。 大多数现代前端开发建设工具已经包括了内置的手表功能(建造,上卷,网络包装,包裹等),可以被服务器机器人所利用. 举例来说 [滚动](https://rollupjs.org/guide/en/),参见 [这里](https://npmcn.com/example/rollup.config.js)。 。 。 .

除了建造工具,你还可以使用类似的东西 [廉价表](https://github.com/Conduitry/cheap-watch) 或者说 [监视列表](https://github.com/lukeed/watchlist)。使用监视列表的例子如下:

```js
import servbot from 'servbot';
import { watch } from 'watchlist';

const server = servbot({
    root: './example/static/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);

(async () => {
    await watch(['./example/static/'], async () => {
        console.log('change detected! reloading...');
        server.reload();
    });
})();
```

## 待办

-   对SPA进行更好的测试
-   HTTP/2 支持

## 常见问题

### @frangio/servbot 是什么？

一个用于本地静态站点开发的小型 Dev 服务器脚本

### 如何安装 @frangio/servbot？

在项目目录运行 npm install @frangio/servbot，或使用 pnpm add / yarn add / bun add。

### @frangio/servbot 支持 TypeScript 吗？

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

### @frangio/servbot 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @frangio/servbot 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=12\.x。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @frangio/servbot 可以商用吗？

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

### @frangio/servbot 的下载量有多少？

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

### @frangio/servbot 还在维护吗？

最新版本 0\.3\.0-1 发布于 2025/06/06（1\.4 年前）；至今共发布 4 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/09/18。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

