esbuild-plugin-html icon indicating copy to clipboard operation
esbuild-plugin-html copied to clipboard

Feature Request: Option to cleanup injected sources in build output

Open cinderblock opened this issue 1 year ago • 2 comments

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(() => {}),
    );
  },
},

cinderblock avatar Sep 26 '24 08:09 cinderblock

(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...

egnor avatar Feb 17 '25 08:02 egnor

I don't remember for sure, but yes probably meant inline. It's been a minute since I've played with this.

cinderblock avatar Feb 17 '25 10:02 cinderblock