Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Kele-Bingtang opened this issue Mar 22, 2025 · 0 comments

Comments

@Kele-Bingtang
Copy link

Kele-Bingtang commented Mar 22, 2025

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();
        });
    },
  }
}
@Kele-Bingtang Kele-Bingtang changed the title Vite 插件的 configureServer 钩子里执行 await server.restart() 失败 在 Vite 插件的 configureServer 钩子里执行 server.restart() 报错 MiniSearch: duplicate ID xx Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant