esbuild
esbuild copied to clipboard
`esbuild.serve` does not emit any URLs / ports, even with `logLevel: 'info'`
The ClI works
❯ npx esbuild --serve --bundle index.js --outdir=a
> Local: http://127.0.0.1:8000/
> Network: http://10.9.8.45:8000/
The API doesn't output anything:
❯ WATCH=true node esbuild.config.mjs
// nothing
//esbuild.config.mjs
import process from 'node:process';
import esbuild from 'esbuild';
const serve = {
servedir: 'public',
};
const build = {
entryPoints: ['index.js'],
outdir: 'public',
logLevel: 'info',
};
if (process.env.WATCH === 'true') {
await esbuild.serve(serve, build);
} else {
await esbuild.build(build);
}
Any config to make it work? Or is this functionality missing?
The CLI just calls the public API like you are doing, and then pretty-prints the returned address and port:
https://github.com/evanw/esbuild/blob/f730c03dc7be43c3c908fbd6e106120a99ebb4a0/pkg/cli/cli_impl.go#L1320-L1355
You are welcome to print it yourself if you'd like, using whatever formatting you want. The host and port are returned from serve here:
https://github.com/evanw/esbuild/blob/f730c03dc7be43c3c908fbd6e106120a99ebb4a0/lib/shared/types.ts#L238-L244
This is documented here: https://esbuild.github.io/api/#serve-return-values
Thank you for the solution, but that feels like I’m rewriting core functionality and it’s not super straightforward either https://thewebdev.info/2022/02/26/how-to-get-local-ip-address-in-node-js/