41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
// @ts-check
|
|
import { resolvePath } from '@kevisual/use-config';
|
|
|
|
const entry = 'src/index.ts';
|
|
const naming = 'app';
|
|
const external = ['pg', 'sqlite3', 'ioredis', 'pm2'];
|
|
/**
|
|
* @type {import('bun').BuildConfig}
|
|
*/
|
|
await Bun.build({
|
|
target: 'node',
|
|
format: 'esm',
|
|
entrypoints: [resolvePath(entry, { meta: import.meta })],
|
|
outdir: resolvePath('./dist', { meta: import.meta }),
|
|
naming: {
|
|
entry: `${naming}.js`,
|
|
},
|
|
external,
|
|
// 启用模块转换和优化
|
|
minify: false,
|
|
splitting: false,
|
|
// sourcemap: 'external',
|
|
// 处理 CommonJS 到 ESM 的转换
|
|
plugins: [{
|
|
name: 'transform-requires',
|
|
setup(build) {
|
|
// 转换内置模块为 node: 前缀
|
|
build.onResolve({ filter: /^(path|fs|module|url|util|crypto|stream|buffer|events|http|https|net|os|querystring|zlib|cluster|child_process|worker_threads|perf_hooks|inspector|dgram|dns|tls|readline|repl|process|assert|vm|timers|constants|string_decoder|punycode|v8)$/ }, args => {
|
|
return {
|
|
path: `node:${args.path}`,
|
|
external: true
|
|
}
|
|
});
|
|
}
|
|
}]
|
|
});
|
|
|
|
// const cmd = `dts -i src/index.ts -o app.d.ts`;
|
|
// const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
|
|
// execSync(cmd, { stdio: 'inherit' });
|