Skip to content

Instantly share code, notes, and snippets.

@Loskir
Created July 23, 2023 19:15
Show Gist options
  • Save Loskir/4911b5c4e598939e39237af98c7d2874 to your computer and use it in GitHub Desktop.
Save Loskir/4911b5c4e598939e39237af98c7d2874 to your computer and use it in GitHub Desktop.
Using esbuild to build a node.js project
import { build } from 'esbuild'
import { glob } from 'glob'
import { rimraf } from 'rimraf'
async function main() {
console.time('build')
await rimraf('./dist')
const globOptions = { ignore: ['node_modules/**', 'dist/**'] }
const files = await glob('**/*.{js,ts,json}', globOptions)
await build({
bundle: false,
format: 'cjs',
platform: 'node',
outdir: 'dist',
target: 'es2020',
entryPoints: files,
loader: {
'.json': 'copy',
'.d.ts': 'copy'
}
})
console.timeEnd('build')
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment