返回 slidev
tsdown.config.ts
根目录 / packages / vscode / tsdown.config.ts
1 import { existsSync } from 'node:fs'
2 import { copyFile, mkdir, writeFile } from 'node:fs/promises'
3 import process from 'node:process'
4 import { fileURLToPath } from 'node:url'
5 import { resolvePath } from 'mlly'
6 import { join } from 'pathe'
7 import { defineConfig } from 'tsdown'
8 import { generateCodeblockPatch } from './syntaxes/codeblock-patch.ts'
9
10 export default defineConfig({
11 entry: {
12 'index': 'src/index.ts',
13 'language-server': 'language-server/bin.ts',
14 },
15 format: 'cjs',
16 target: 'node20',
17 clean: true,
18 minify: process.env.NODE_ENV === 'production',
19 sourcemap: true,
20 external: [
21 'vscode',
22 ],
23 alias: {
24 '@slidev/parser/fs': fileURLToPath(new URL('../parser/src/fs.ts', import.meta.url)),
25 '@slidev/parser/core': fileURLToPath(new URL('../parser/src/core.ts', import.meta.url)),
26 '@slidev/parser/types': fileURLToPath(new URL('../parser/src/types.ts', import.meta.url)),
27 '@slidev/parser': fileURLToPath(new URL('../parser/src/index.ts', import.meta.url)),
28 },
29 plugins: [
30 {
31 name: 'umd2esm',
32 resolveId: {
33 filter: {
34 id: /^(vscode-.*-languageservice|vscode-languageserver-types|jsonc-parser)/,
35 },
36 async handler(source, importer) {
37 const pathUmdMay = await resolvePath(source, { url: importer })
38 // Call twice the replace is to solve the problem of the path in Windows
39 const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\')
40 return { id: pathEsm }
41 },
42 },
43 },
44 ],
45 async onSuccess() {
46 const assetsDir = join(import.meta.dirname, '../../assets')
47 const resDir = join(import.meta.dirname, './dist/res')
48
49 if (!existsSync(resDir))
50 await mkdir(resDir, { recursive: true })
51
52 for (const file of ['logo-mono.svg', 'logo-mono-dark.svg', 'logo.png', 'logo.svg'])
53 await copyFile(join(assetsDir, file), join(resDir, file))
54
55 await writeFile(
56 join(import.meta.dirname, 'syntaxes/codeblock-patch.json'),
57 JSON.stringify(generateCodeblockPatch(), null, 2),
58 )
59 },
60 })
61
61 lines TYPESCRIPT