Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build script using esbuild and ts-morph to bundle library code.
import glob from 'fast-glob'
import { build } from 'esbuild'
import { Project } from 'ts-morph'
const project = new Project({
compilerOptions: {
outDir: 'dist',
emitDeclarationOnly: true,
},
tsConfigFilePath: './tsconfig.json',
})
project.emit()
build({
entryPoints: await glob(['src/**/*.{ts,tsx}', '!src/**/*.test.ts']),
outdir: 'dist',
format: 'esm',
watch: process.argv.includes('--watch')
? {
onRebuild: async (error) => {
if (error) {
console.error('watch build failed:', error)
} else {
await Promise.all(
project
.getSourceFiles()
.map((sourceFile) => sourceFile.refreshFromFileSystem())
)
project.emit()
}
},
}
: undefined,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment