esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Provide a way to parse command line options into BuildOptions

Open hagabaka opened this issue 10 months ago • 1 comments

It seems that if you use a build script and want it to also handle command line options, you have to write code to handle them yourself (#3383). It would be nice if there is an API to parse BuildOptions from process.argv, so that a build script can just use that and merge them into options parsed to build.

My use case is that I want to have a "build" script in package.json, and want to sometimes invoke it with the --watch option to use the watch mode.

hagabaka avatar Feb 14 '25 02:02 hagabaka

esbuild's command args style are quite simple (it doesn't parse spaced arguments like --key value). You can implement a parser which behave exactly the same as esbuild easily: https://github.com/hyrious/esbuild-dev/blob/main/src/args.ts

Here's another implementation used in esbuild.try: https://github.com/esbuild/esbuild.github.io/blob/main/src/try/options.ts#L51

hyrious avatar Feb 14 '25 02:02 hyrious