esbuild-plugin-html
esbuild-plugin-html copied to clipboard
Feature Request: Option to cleanup injected sources in build output
It would be nice, when inject: true, to not have the source files littered around still. One option would be to use an alternate folder, but why bother?
I wrote a quick "plugin" to do this:
{
name: 'Cleanup Plugin',
setup(build) {
build.onEnd(res =>
Promise.all(
Object.keys(res.metafile?.outputs ?? {}).map(file =>
unlink(file).catch(e => logger.warn(`Failed to clean up ${file}: ${e.message}`)),
),
).then(() => {}),
);
},
},
(Did you mean inline: true instead of inject: true?)
I agree that having things littered around is weird, at the same time deleting esbuild's outputs is also a bit odd. In a more integrated system HTML would actually be the output type?? But esbuild doesn't allow plugins to do that...
I don't remember for sure, but yes probably meant inline. It's been a minute since I've played with this.