From c82da2f6ed7aee43033dbe318b33f62f4104d834 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B4=AE=E7=94=9F=EF=BC=88=E5=AD=90=E8=99=9A=EF=BC=89?=
<2234839456@qq.com>
Date: Sat, 15 Aug 2026 16:22:17 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20demo=20=E5=8A=A0=E6=BA=90=E7=A0=81/npm?=
=?UTF-8?q?=20=E9=93=BE=E6=8E=A5=EF=BC=8C=E6=9E=84=E5=BB=BA=E6=97=B6?=
=?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=BF=9B=E4=B8=BB=E7=AB=99=20dist/leafer-dem?=
=?UTF-8?q?o/=EF=BC=88vite=20=E6=8F=92=E4=BB=B6=20+=20sitemap=20=E8=B7=AF?=
=?UTF-8?q?=E7=94=B1=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/leafer-x-webfont/demo/index.html | 4 +++-
scripts/leafer-demo-plugin.ts | 27 +++++++++++++++++++++++
vite.config.ts | 4 ++++
3 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 scripts/leafer-demo-plugin.ts
diff --git a/packages/leafer-x-webfont/demo/index.html b/packages/leafer-x-webfont/demo/index.html
index 013da51..498a905 100644
--- a/packages/leafer-x-webfont/demo/index.html
+++ b/packages/leafer-x-webfont/demo/index.html
@@ -29,7 +29,9 @@
LeaferJS 中文字体插件 —— 画布里的 Text 用什么字体,就只加载那几个字的子集(6 字 ≈ 6KB,而非 16MB)。
服务端:webfont.shenzilong.cn
- / GitHub
+ / 插件源码
+ / 本页源码
+ / npm
diff --git a/scripts/leafer-demo-plugin.ts b/scripts/leafer-demo-plugin.ts
new file mode 100644
index 0000000..7d26b26
--- /dev/null
+++ b/scripts/leafer-demo-plugin.ts
@@ -0,0 +1,27 @@
+/**
+ * 构建时把 packages/leafer-x-webfont/demo/index.html 复制进主站 dist。
+ *
+ * 该 demo 是零构建的纯静态单文件(依赖全走 jsDelivr CDN),不参与 vite-ssg 管线;
+ * 挂到主站 /leafer-demo/ 路径下,后端 staticFileMiddleware 已支持目录 → index.html 解析。
+ * 若 demo 未来变成多文件,需改为 copy 整个目录。
+ */
+import type { Plugin } from "vite";
+import { copyFileSync, mkdirSync } from "node:fs";
+import { dirname, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+export function leaferDemoPlugin(): Plugin {
+ const rootDir = dirname(dirname(fileURLToPath(import.meta.url)));
+ const source = resolve(rootDir, "packages/leafer-x-webfont/demo/index.html");
+ const target = resolve(rootDir, "dist/leafer-demo/index.html");
+
+ return {
+ name: "copy-leafer-demo",
+ apply: "build",
+ closeBundle() {
+ mkdirSync(dirname(target), { recursive: true });
+ copyFileSync(source, target);
+ console.log(`[leafer-demo] copied → dist/leafer-demo/index.html`);
+ },
+ };
+}
diff --git a/vite.config.ts b/vite.config.ts
index e3f4327..473cead 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -4,6 +4,7 @@ import vue from "@vitejs/plugin-vue";
import { pilot } from "vite-plugin-pilot";
import commonjs from "vite-plugin-commonjs";
import { sitemapPlugin } from "./scripts/sitemap-plugin";
+import { leaferDemoPlugin } from "./scripts/leafer-demo-plugin";
/**
* 引入 vite-ssg 的类型声明 ——
* vite-ssg 内部通过 declaration merging 给 vite 的 UserConfig 扩展了 ssgOptions 字段,
@@ -22,6 +23,7 @@ const sitemapRoutes = [
{ path: "/offline-subset", changefreq: "weekly" as const, priority: 0.8 },
{ path: "/docs", changefreq: "weekly" as const, priority: 0.8 },
{ path: "/demo", changefreq: "monthly" as const, priority: 0.6 },
+ { path: "/leafer-demo/", changefreq: "monthly" as const, priority: 0.6 },
];
export default defineConfig({
@@ -132,6 +134,8 @@ export default { isInited: () => false, init: () => Promise.resolve(), encode: (
},
},
sitemapPlugin(sitemapRoutes),
+ /** 把 leafer 插件 demo 复制进 dist/leafer-demo/(纯静态单文件,不走 vite-ssg 管线) */
+ leaferDemoPlugin(),
/**
* 构建时替换 index.html 中的时间戳占位符
*