Skip to content

Instantly share code, notes, and snippets.

@ValentaTomas
Last active December 4, 2021 12:56
Show Gist options
  • Save ValentaTomas/5c235c876e549b7d3f0d07f757c03f46 to your computer and use it in GitHub Desktop.
Save ValentaTomas/5c235c876e549b7d3f0d07f757c03f46 to your computer and use it in GitHub Desktop.
Esbuild build script for Node.js projects
#!/usr/bin/env node
const esbuild = require('esbuild');
const path = require('path');
const makeAllPackagesExternalPlugin = {
name: 'make-all-packages-external',
setup(build) {
const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../"
build.onResolve({ filter }, args => ({ path: args.path, external: true }));
},
}
esbuild
.build({
bundle: true,
minify: true,
tsconfig: 'tsconfig.json',
platform: 'node',
target: 'node16.3',
sourcemap: false,
treeShaking: true,
plugins: [makeAllPackagesExternalPlugin],
outdir: 'lib',
entryPoints: [path.join('src', 'index.ts')],
})
.catch(() => process.exit(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment