-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtsup.config.ts
More file actions
24 lines (23 loc) · 919 Bytes
/
tsup.config.ts
File metadata and controls
24 lines (23 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
splitting: false,
sourcemap: true,
clean: true,
target: 'node18',
outDir: 'dist',
onSuccess: async () => {
// Patch CJS output so `require('classificator')` returns the factory function directly.
// Insert before the sourcemap comment so debuggers can still find source maps.
const fs = await import('fs')
const cjs = fs.readFileSync('dist/index.cjs', 'utf8')
const patch = '\nif (module.exports.default) { Object.assign(module.exports.default, module.exports); module.exports = module.exports.default; }\n'
const sourcemapMatch = cjs.match(/\n\/\/# sourceMappingURL=.*$/)
const patched = sourcemapMatch
? cjs.replace(sourcemapMatch[0], patch + sourcemapMatch[0])
: cjs + patch
fs.writeFileSync('dist/index.cjs', patched)
},
})