feat: demo 加源码/npm 链接,构建时复制进主站 dist/leafer-demo/(vite 插件 + sitemap 路由)

This commit is contained in:
崮生(子虚) 2026-08-15 16:22:17 +08:00
parent 64b8bcdbe8
commit c82da2f6ed
3 changed files with 34 additions and 1 deletions

View File

@ -29,7 +29,9 @@
<p class="sub">
LeaferJS 中文字体插件 —— 画布里的 Text 用什么字体就只加载那几个字的子集6 字 ≈ 6KB而非 16MB
服务端:<a href="https://webfont.shenzilong.cn" target="_blank">webfont.shenzilong.cn</a>
/ <a href="https://github.com/2234839/web-font" target="_blank">GitHub</a>
/ <a href="https://github.com/2234839/web-font/tree/new/packages/leafer-x-webfont" target="_blank">插件源码</a>
/ <a href="https://github.com/2234839/web-font/blob/new/packages/leafer-x-webfont/demo/index.html" target="_blank">本页源码</a>
/ <a href="https://www.npmjs.com/package/leafer-x-webfont" target="_blank">npm</a>
</p>
<div class="panel">

View File

@ -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`);
},
};
}

View File

@ -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
*