/** * 把 Vditor 的运行时资源同步到 public/vditor。 * * 为什么不用它的默认 CDN:Vditor 会按需去 `unpkg.com/vditor@<版本>` 拉 lute(3.7 MB * 的 Markdown 引擎)、语言包和图标。内网、离线、或者被墙的环境下,编辑器会一直停在 * 加载状态,而失败信息只有控制台一行 404。 * * 这里只复制真正需要的几样,`public/vditor` 不进版本库(见 .gitignore), * 由 `predev` / `prebuild` 自动生成,升级 Vditor 后自然跟着更新。 */ import { copyFileSync, existsSync, mkdirSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); const webRoot = join(here, ".."); const source = join(webRoot, "node_modules", "vditor", "dist"); const target = join(webRoot, "public", "vditor", "dist"); const files = [ "js/lute/lute.min.js", "js/i18n/zh_CN.js", "js/i18n/en_US.js", "js/icons/ant.js", "js/icons/material.js", ]; if (!existsSync(source)) { console.error("[vendor-vditor] 没找到 node_modules/vditor,先跑一次 npm install"); process.exit(1); } let copied = 0; for (const rel of files) { const from = join(source, rel); if (!existsSync(from)) { console.warn(`[vendor-vditor] 跳过(包里没有): ${rel}`); continue; } const to = join(target, rel); mkdirSync(dirname(to), { recursive: true }); copyFileSync(from, to); copied += 1; } console.log(`[vendor-vditor] 已同步 ${copied} 个文件到 public/vditor/dist`);