2026-04-02 20:59:23 +08:00

56 lines
1.3 KiB
TypeScript

import { defineConfig, type UserConfig } from 'tsdown'
import { argv } from '../../scripts/tsdown-args'
const config = [
{ dir: 'composables', files: ['codeRepl.ts', 'pdf.ts', 'rustRepl.ts', 'size.ts', 'audio.ts', 'demo.ts', 'mark.ts', 'decrypt.ts'] },
{ dir: 'utils', files: ['http.ts', 'link.ts', 'sleep.ts'] },
{ dir: '', files: ['index.ts', 'options.ts'] },
]
const clientExternal = [
/.*\.vue$/,
/composables\/.*\.js$/,
/utils\/.*\.js$/,
/.*\/options\.js$/,
/shared\/index\.js$/,
]
export default defineConfig((cli) => {
const DEFAULT_OPTIONS: UserConfig = {
dts: true,
sourcemap: false,
format: 'esm',
clean: !cli.watch,
fixedExtension: false,
}
const options: UserConfig[] = []
// shared
options.push({
...DEFAULT_OPTIONS,
entry: ['./src/shared/index.ts'],
outDir: './lib/shared',
})
if (argv.node) {
options.push({
...DEFAULT_OPTIONS,
entry: ['./src/node/index.ts'],
outDir: './lib/node',
target: 'node20.19.0',
deps: { neverBundle: ['markdown-it', /^@?vuepress/] },
})
}
if (argv.client) {
options.push(...config.map(({ dir, files }) => ({
...DEFAULT_OPTIONS,
entry: files.map(file => `./src/client/${dir}/${file}`),
outDir: `./lib/client/${dir}`,
deps: { neverBundle: clientExternal },
})))
}
return options
})