返回 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 deps: {
21 neverBundle: [
22 'vscode',
23 ],
24 },
25 alias: {
26 '@slidev/parser/fs': fileURLToPath(new URL('../parser/src/fs.ts', import.meta.url)),
27 '@slidev/parser/core': fileURLToPath(new URL('../parser/src/core.ts', import.meta.url)),
28 '@slidev/parser/types': fileURLToPath(new URL('../parser/src/types.ts', import.meta.url)),
29 '@slidev/parser': fileURLToPath(new URL('../parser/src/index.ts', import.meta.url)),
30 },
31 plugins: [
32 {
33 name: 'umd2esm',
34 resolveId: {
35 filter: {
36 id: /^(vscode-.*-languageservice|vscode-languageserver-types|jsonc-parser)/,
37 },
38 async handler(source, importer) {
39 const pathUmdMay = await resolvePath(source, { url: importer })
40 // Call twice the replace is to solve the problem of the path in Windows
41 const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\')
42 return { id: pathEsm }
43 },
44 },
45 },
46 ],
47 async onSuccess() {
48 const assetsDir = join(import.meta.dirname, '../../assets')
49 const resDir = join(import.meta.dirname, './dist/res')
50
51 if (!existsSync(resDir))
52 await mkdir(resDir, { recursive: true })
53
54 for (const file of [
55 'logo-mono.svg',
56 'logo-mono-dark.svg',
57 'logo.png',
58 'logo.svg',
59 ])
60 await copyFile(join(assetsDir, file), join(resDir, file))
61
62 await writeFile(
63 join(import.meta.dirname, 'syntaxes/codeblock-patch.json'),
64 JSON.stringify(generateCodeblockPatch(), null, 2),
65 )
66 },
67 })
68
68 lines TYPESCRIPT