Last active
December 4, 2021 12:56
-
-
Save ValentaTomas/5c235c876e549b7d3f0d07f757c03f46 to your computer and use it in GitHub Desktop.
Esbuild build script for Node.js projects
This file contains 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
#!/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