This commit is contained in:
2026-08-29 16:20:33 +08:00
commit cba31428dc
52 changed files with 6553 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* 客户端 bundle 包装脚本
* 将 tsdown 生成的 CJS bundle 包装为 DSH 客户端模块系统格式:
* window.__ModuleLoader__.load({ id, factory: (require) => {...} })
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = dirname(dirname(fileURLToPath(import.meta.url)));
const bundlePath = join(root, 'lib/client/index.js');
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
const bundle = readFileSync(bundlePath, 'utf8');
const wrapped = 'window.__ModuleLoader__.load({\n' +
' id: "' + pkg.name + '",\n' +
' factory: (require) => {\n' +
' var module = { exports: {} };\n' +
' var exports = module.exports;\n' +
' Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });\n' +
bundle + '\n' +
' return module.exports;\n' +
' }\n' +
'});\n';
writeFileSync(bundlePath, wrapped, 'utf8');
console.log('client bundle wrapped ->', bundlePath, '(' + wrapped.length + ' bytes)');