esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

ESBuild onEnd Callback: `outputFiles` is undefined.

Open mayank1513 opened this issue 9 months ago • 1 comments

Here is my setup

               await esbuild.build({
			format: "cjs",
			target: "es2019",
			sourcemap: false,
			bundle: true,
			minify: true,
			plugins: [react18Plugin()],
			entryPoints: await glob("../esbuild-plugin-react18-example/src/**/*.*"),
			publicPath: "https://my.domain/static/",
			external: ["react", "react-dom"],
			outdir: "./dist/default",
			metafile: true,
		});
// plugin snippet
                  build.onEnd(result => {
			console.log("onEnd -- start", result);
                        ...
                  }

outputFiles: undefined

outputFiles gets an array when I pass write: false in options. However, there is no output in that case.

mayank1513 avatar Sep 25 '23 15:09 mayank1513

outputFiles gets an array when I pass write: false in options. However, there is no output in that case.

Yes, you have 2 choices:

  1. Set write: false, then write them out by yourself.

    I did that before: https://github.com/hyrious/esbuild-repl/blob/f6a2783c9d0108a3b1596408634718bf89feaffc/scripts/plugins/emits.ts#L67-L71

  2. Let esbuild writes them out, and you can analyze the output directory and the metafile.

hyrious avatar Oct 04 '23 16:10 hyrious

Add this in the beginning of setup function.

const write = build.initialOptions.write;
build.initialOptions.write = false;

You need to manually write to the files in onEnd if write was true initially.

mayank1513 avatar Mar 15 '24 17:03 mayank1513