-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
81 lines (78 loc) · 2.74 KB
/
Copy pathvite.config.js
File metadata and controls
81 lines (78 loc) · 2.74 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2026 Hudson River Trading LLC. See LICENSE.
import { readFileSync } from "fs";
import { resolve, dirname } from "path";
import { defineConfig } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
function htmlInclude() {
const includedFiles = [];
return {
name: "html-include",
transformIndexHtml: {
order: "pre",
handler(html, ctx) {
const root = ctx.filename ? dirname(ctx.filename) : process.cwd();
includedFiles.length = 0;
// Include HTML partials
html = html.replace(/<!--include\s+([\w.\/\-]+)\s*-->/g, (_, file) => {
const path = resolve(root, file);
includedFiles.push(path);
return readFileSync(path, "utf-8");
});
// Embed jsbeeb iframes from .ssd files
html = html.replace(/<!--jsbeeb\s+([\w.\/\-]+)\s*-->/g, (_, file) => {
const path = resolve(root, file);
includedFiles.push(path);
const b64 = readFileSync(path).toString("base64");
return `<iframe src="https://bbc.godbolt.org/?1#embed&autoboot&disc1=b64data:${b64}" width="640" height="512" style="border:none" loading="lazy"></iframe>`;
});
return html;
},
},
configureServer(server) {
server.watcher.add(resolve(process.cwd(), "sections"));
server.watcher.add(resolve(process.cwd(), "research"));
server.watcher.on("change", (file) => {
if (includedFiles.includes(file)) {
server.ws.send({ type: "full-reload" });
}
});
},
};
}
export default defineConfig({
base: "./",
// Restrict dep pre-bundling to our own entry - otherwise Vite's scanner
// walks into reveal.js/test/test.html and fails on its qunit imports.
optimizeDeps: {
entries: ["index.html"],
},
build: {
// reveal.js's highlight.mjs is a pre-bundled ~1MB artifact with all
// highlight.js languages baked in via side-effect registration - not
// tree-shakeable. Lift the warning above that.
chunkSizeWarningLimit: 1200,
},
plugins: [
htmlInclude(),
viteStaticCopy({
targets: [
{ src: "reveal.js/dist", dest: "reveal.js" },
// Vite's HTML scanner only rewrites known asset attributes (<img src>
// etc.), so reveal.js's data-background-image/video/iframe URLs are
// left untouched and never copied to dist. Copy the whole images dir
// verbatim so any data-background-* reference Just Works.
{ src: "images", dest: "." },
],
}),
{
name: "md-reload",
configureServer(server) {
server.watcher.add("*.md");
server.watcher.on(
"change",
(file) => file.endsWith(".md") && server.ws.send({ type: "full-reload" }),
);
},
},
],
});