mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 14:53:32 +08:00
feat: demo 加源码/npm 链接,构建时复制进主站 dist/leafer-demo/(vite 插件 + sitemap 路由)
This commit is contained in:
parent
64b8bcdbe8
commit
c82da2f6ed
@ -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">
|
||||
|
||||
27
scripts/leafer-demo-plugin.ts
Normal file
27
scripts/leafer-demo-plugin.ts
Normal 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`);
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -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 中的时间戳占位符
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user