Skip to content

在 Vite 插件的 configureServer 钩子里执行 server.restart() 报错 MiniSearch: duplicate ID xx #4642

Open
@Kele-Bingtang

Description

@Kele-Bingtang

1.6.3 版本。

我在 Vite 插件里使用 configureServer 钩子判断 md 文件是否新增或者删除,如果有则重启服务,但是之前 await server.restart() 报错:MiniSearch: duplicate ID /01.指南/01.指南 - 使用/07.使用 - 权限认证#设计思路

代码如下;

import { type Plugin, type ViteDevServer } from "vite";

export default function VitePluginVitePressMdWatch(): Plugin {
  return {
    name: "vite-plugin-vitepress-md-watch",
    configureServer(server: ViteDevServer) {
      server.watcher.add("*.md");
      server.watcher
        .on("add", async path => {
          // 过滤非 .md 文件
          if (!path.endsWith(".md")) return;
          // 重启服务器
          await server.restart();
        })
        .on("unlink", async path => {
          // 过滤非 .md 文件
          if (!path.endsWith(".md")) return;
          // 重启服务器
          await server.restart();
        });
    },
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions