rsms / estrella

Lightweight and versatile build tool based on the esbuild compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get build result with write: false?

vforsh opened this issue · comments

It's not an issue exactly but a question.

I want to modify esbuild output after the build. I was expecting that I can get the output with onEnd and buildResult. But it contains just errors and warnings (which are both empty arrays in my case because the build was successful).

Thanks for the excellent tool!

Here how I do it with plain esbuild:

esbuild.build({
	entryPoints: ["phaser.custom.config.js"],
	globalName: "Phaser",
	format: "iife",
	bundle: true,
	target: "es5",
	write: false,
}).then(buildResult => {
	let content = buildResult.outputFiles[0].text
	
	// now I can modify content, transpile it with Babel for example
})

The issue is that estrella doesn't expose outputFiles property.

It's been possible when invoking estrella as a CLI program.
With the latest changes (not yet released when I'm writing this) you can now also output to either stdout or to the API (onEnd) when using estrella from a build script.

Example build invocations

No outfile (or outdir) causes output to be delivered as text to onEnd:

build({
  entry: "main.js",
  sourcemap: true,
  onEnd(config, result) {
    console.log("output js:", result.js.trim())
    console.log("output source map:", JSON.parse(result.map))
  },
})

With outfile:"-" output is written to stdout:

build({
  entry: "main.js",
  outfile: "-",
})

Published in v1.3.0