-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.util.ts
32 lines (25 loc) · 888 Bytes
/
vite.util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { PluginOption } from "vite";
import fs from 'fs';
import path from 'path';
export async function collectHTMLFiles(dirs: string[]): Promise<string[]> {
const files: string[] = [];
for (const dir of dirs) {
const entries = await fs.promises.readdir(dir);
for (const entry of entries) {
const entryPath = path.join(dir, entry);
const stats = await fs.promises.stat(entryPath);
if (stats.isDirectory()) {
const nestedFiles = await collectHTMLFiles([entryPath]);
files.push(...nestedFiles);
} else if (entry.endsWith('.html')) {
files.push(entryPath);
}
}
}
return files;
}
export const ForceReloadPlugin: PluginOption = {
handleHotUpdate({ server }) {
server.ws.send({ type: "full-reload" });
}
} as PluginOption;