When using "Dynamic Routes" to render raw content, how to keep hot reload working. #4569
Replies: 3 comments 8 replies
-
Currently not possible without custom watcher or weird hacks. If you just want to include markdown files, you can use - https://vitepress.dev/guide/markdown#markdown-file-inclusion Simpler hack if you want to keep using path loaders, you can append something like this to your content |
Beta Was this translation helpful? Give feedback.
-
[name].paths.ts import fs from "fs";
import path from "path";
import { defineRoutes } from "vitepress";
const regex = /components\/([^/]+)/;
export default defineRoutes({
watch: [path.resolve(process.cwd(), "../ui/components/*/README.en.md")],
paths(watchFiles) {
console.log("en rebuild", watchFiles);
const paths = watchFiles.filter((p) => {
const last = p.split("/").pop();
return !last?.startsWith("_") && !last?.endsWith("ts");
});
const demos = paths.map((p) => {
const content = fs.readFileSync(p, "utf-8");
const match = p.match(regex);
const componentName = match?.[1];
return {
componentName,
content,
};
});
return demos.map((d) => ({
params: { name: d.componentName as string },
content: d.content,
}));
},
}); <!-- @content --> HMR cannot be triggered when the watch file is updated @brc-dd |
Beta Was this translation helpful? Give feedback.
-
https://github.com/jianxing-xu/vitepress-pr-4569-test @brc-dd I initialized a repository and modified the version to 2.0.0-alpha.3
and I use [name].paths.ts and the error appears
Failed to load /home/jianxing/space/vitepress-p-4569/@test/[name].paths.ts: I use the .mts suffix to be fine |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It didn't work.
<!-- @content -->
Beta Was this translation helpful? Give feedback.
All reactions