Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created February 24, 2022 02:48
Show Gist options
  • Save souporserious/7f38e4f6b4739f82078cf6fee014537a to your computer and use it in GitHub Desktop.
Save souporserious/7f38e4f6b4739f82078cf6fee014537a to your computer and use it in GitHub Desktop.
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