52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
/**
|
||
* 构建客户端包:esbuild(CJS / browser / 平台模块外置)+ dsh 模块加载器包装。
|
||
* 包装协议与 dsh 官方 tsdown 产物一致:
|
||
* window.__ModuleLoader__.load({ id, factory: (require) => { ... return module.exports } })
|
||
*/
|
||
|
||
import { build } from 'esbuild'
|
||
import { dirname, join } from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||
const PKG_ID = '@gyxx/dsh-plugin-gyxx-workbench'
|
||
|
||
// dsh 平台共享模块表(packages/client/web/src/platform.ts 的 PLATFORM_MODULES)
|
||
const PLATFORM_EXTERNALS = [
|
||
'react',
|
||
'react/jsx-runtime',
|
||
'react-dom',
|
||
'react-dom/client',
|
||
'@deepseek-ai/cordis',
|
||
'@deepseek-ai/dsh-client-store',
|
||
'@deepseek-ai/dsh-client-ui-slots',
|
||
'@deepseek-ai/dsh-client-ui-primitives',
|
||
]
|
||
|
||
await build({
|
||
absWorkingDir: root,
|
||
entryPoints: ['client/src/index.jsx'],
|
||
bundle: true,
|
||
format: 'cjs',
|
||
platform: 'browser',
|
||
target: 'es2020',
|
||
outfile: 'lib/client.js',
|
||
external: PLATFORM_EXTERNALS,
|
||
loader: { '.css': 'text' },
|
||
jsx: 'automatic',
|
||
sourcemap: true,
|
||
minify: false,
|
||
define: {
|
||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
|
||
},
|
||
banner: {
|
||
// dsh 浏览器加载器只给 factory 传 require(返回值即模块导出),
|
||
// CJS 的 module/exports 垫片必须由包体自带(与官方 tsdown 产物一致)。
|
||
js: `window.__ModuleLoader__.load({ id: ${JSON.stringify(PKG_ID)}, factory: (require) => {\nvar module = { exports: {} };\nvar exports = module.exports;`,
|
||
},
|
||
footer: { js: 'return module.exports; } });' },
|
||
logLevel: 'info',
|
||
})
|
||
|
||
console.log('built lib/client.js')
|