@frangio/servbot

中文文档
0.3.0-1发布于 2025/06/06MITTypeScriptESM + CJS零依赖近 30 天下载 7000

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

中文使用文档
文档目录4 节
  1. 安装
  2. 使用量
  3. 使用手动重装
  4. 待办

服务器

一个用于本地静态站点开发的小型dev服务器. 基本上是一个包裹周围 页:1 服务器. 叉线 服务器。 。 。 .

import servbot from 'servbot';

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

server.listen(8080);

这是一个有观点的叉子,有一些有意排除和范围较小,一些想法取自: 本地w/服务器。 。 。 .

安装

npm install servbot --save-dev

使用量

参见类型 指数.d.ts. servbot接受一个单一的论据, ServbotOptions;并返回实例 ServbotServer。关于默认选项,见下文.

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 不包含一个文件监视器,以便在文件更改时自动重新加载您的应用程序,而是包含一个 手动 重新装入特性 。 大多数现代前端开发建设工具已经包括了内置的手表功能(建造,上卷,网络包装,包裹等),可以被服务器机器人所利用. 举例来说 滚动,参见 这里。 。 。 .

除了建造工具,你还可以使用类似的东西 廉价表 或者说 监视列表。使用监视列表的例子如下:

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 共发布 4 个版本,首次发布于 2022/09/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.0-1latest2025/06/061.4 年前
0.3.0-0next2022/11/024 年前
0.2.52022/09/184 年前
0.2.42022/09/184 年前

关于 @frangio/servbot 的常见问题

@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 和提交记录判断。