-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
53 lines (44 loc) · 1.63 KB
/
tsup.config.ts
File metadata and controls
53 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { defineConfig } from 'tsup'
import { dirname, relative, resolve } from 'path'
import fg from 'fast-glob'
import fs from 'fs'
export default defineConfig({
tsconfig: resolve(__dirname, 'tsconfig.json'),
entry: ['src/**/**/*.ts', '!src/**/**/*.spec.ts'],
external: ['fast-glob', 'yaml', 'chalk'],
format: 'esm',
platform: 'node',
splitting: false,
clean: true,
treeshake: false,
sourcemap: false,
minify: false,
skipNodeModulesBundle: true,
bundle: false,
async onSuccess() {
// fix alias
const files = await fg('dist/**/*.js', { onlyFiles: true })
const alias: Record<string, string> = {}
for (const folder of fs.readdirSync(resolve('dist'))) {
alias[`@/${folder}`] = resolve('dist', folder)
}
for (const file of files.reverse()) {
const folder = dirname(file)
let content = await fs.promises.readFile(file, 'utf-8')
for (const [key, value] of Object.entries(alias)) {
let importPath = relative(folder, value).replace(/\\/g, '/')
importPath = './' + importPath
content = content.replace(new RegExp(key, 'g'), importPath)
}
await fs.promises.writeFile(file, content)
}
// resources
const resources = await fs.promises.readdir(resolve(import.meta.dirname, 'src/templates'))
for (const r of resources) {
await fs.promises.cp(
resolve(import.meta.dirname, 'src/templates', r),
resolve(import.meta.dirname, 'dist/templates', r)
)
}
},
})