web-font/packages/uni-webfont/scripts/sync-uni-modules.mjs
崮生(子虚) 140f84d3c7 feat: uni-app 插件 gs-webfont —— 字体按需加载(子集化)上线准备
- webfont-sdk 引擎修复两处并发池 bug(原版排队分支丢任务;闭包复用会让
  队列真身丢失导致 pending 卡死),新增 per-state provider 与 submitText 分批
- 新增 packages/uni-webfont:字符累积 + uni.loadFontFace 同 family 重载策略,
  串行保序(maxConcurrent=1),二次 loadFont 从引擎播种累积集
- 产物同步 uni_modules/gs-webfont/js_sdk(自包含 ESM+iife+d.ts)
- 端到端验证:mock 全绿;线上真实服务 4 字 → 10.1KB 合法 TTF
2026-08-16 10:34:40 +08:00

33 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 构建后同步:把 dist-bundle 产物写入 uni_modules/gs-webfont/js_sdk/。
* uni_modules 是 DCloud 插件市场的标准目录结构HBuilderX 从这里读插件。
*/
import { readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)))
const esm = resolve(pkgRoot, 'dist-bundle/index.js')
const iife = resolve(pkgRoot, 'dist-bundle/index.iife.js')
const targetDir = resolve(pkgRoot, '../../uni_modules/gs-webfont/js_sdk')
const dts = resolve(pkgRoot, 'dist/index.d.ts')
mkdirSync(targetDir, { recursive: true })
/**
* ESM 版uni-app CLI 工程vite直接 import 用。
* 头部 banner 声明来源,提醒勿手改
*/
const banner = `/**
* gs-webfont —— uni-app 字体按需加载(由 packages/uni-webfont 构建,勿手改)
* 文档https://webfont.shenzilong.cn
*/
`
writeFileSync(resolve(targetDir, 'index.js'), banner + readFileSync(esm, 'utf8'))
/** iife 版HBuilderX 非 CLI 工程经 require/script 引入,挂全局 UniWebFontBundle */
copyFileSync(iife, resolve(targetDir, 'index.iife.js'))
/** d.tsIDE 智能提示 */
copyFileSync(dts, resolve(targetDir, 'index.d.ts'))
console.log(`✓ synced → uni_modules/gs-webfont/js_sdk/`)