How to trigger the first build with esbuild.context

71 views Asked by At

I sometimes just want to build instead of watching how to trigger the build without ctx.watch(). In this code I trigger the build by ctx.watch(), if the watch variable is false then run ctx.dispose() to close esbuild so it just builds without watching. There should be a good and proff way of doing it but idk how.

const ctx = await esbuild.context({
    entryPoints: ["./index.js"],
    outdir: outDir,
    write: false,
    plugins: [
        {
            name: "on-end",
            setup(build) {
                build.onEnd(async (result) => {
                    await processCode(result)
                })
            },
        },
    ],
})
await ctx.watch()
if (!watch) ctx.dispose()
0

There are 0 answers