Created
February 24, 2022 02:48
-
-
Save souporserious/7f38e4f6b4739f82078cf6fee014537a to your computer and use it in GitHub Desktop.
Build script using esbuild and ts-morph to bundle library code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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