Files
dsh-worktable/01_content/build.mjs
T

50 lines
1.7 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.
/**
* dsh-worktable 构建:
* - lib/index.js 服务端 ESM(cordis 插件,健康路由)
* - lib/client.js 客户端单文件 CJS(window.__ModuleLoader__.load 握手;
* react / @deepseek-ai/* 由宿主模块系统提供,保持 external)
* esbuild 走 JS API;pdf.js worker 源码以字符串注入客户端 banner,
* 运行时用 Blob URL 起 module worker(不依赖服务端路由,F5 即生效)。
*/
import { build } from 'esbuild'
import { readFileSync, mkdirSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const here = dirname(fileURLToPath(import.meta.url))
mkdirSync(join(here, 'lib'), { recursive: true })
const clientBanner = {
js: "window.__ModuleLoader__.load({ id: 'dsh-worktable', factory: (require) => { var module = { exports: {} }; var exports = module.exports;",
}
const clientFooter = { js: 'return module.exports; } });' }
await build({
entryPoints: [join(here, 'src/index.ts')],
outfile: 'lib/index.js',
bundle: true,
sourcemap: true,
logLevel: 'info',
platform: 'node',
format: 'esm',
target: ['node22'],
external: ['@deepseek-ai/*', 'node:*', 'ws', 'node-pty'],
})
await build({
entryPoints: [join(here, 'src/client/index.tsx')],
outfile: 'lib/client.js',
bundle: true,
sourcemap: true,
logLevel: 'info',
platform: 'browser',
format: 'cjs',
target: ['es2022'],
jsx: 'automatic',
external: ['@deepseek-ai/*', 'react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'scheduler'],
banner: clientBanner,
footer: clientFooter,
})
console.log('[dsh-worktable build] done: lib/index.js, lib/client.js')