rollup-plugin-visualizer icon indicating copy to clipboard operation
rollup-plugin-visualizer copied to clipboard

Option/hook to allow uploading the generated json data

Open IARI opened this issue 4 months ago • 1 comments

I would like to have a database/platform which keeps the generated json data (+ maybe some CI related environment data, like commit hash, branch name, date, etc)

First I though ot uploading the stats.json with some CI job afterwards, but its a multi-stage docker-in-docker build, and getting build-repoorts out of the build-stage feels like a nightmare.

So I think it makes a lot more sense to just have vite itsself manage this and avoid additional bash. For now I am just using visualizer({ template: 'raw-data' }),

Plus a custom plugin which is run afterwards, where I

  • read stats.json
  • then post the data to some endpoint

It would be super nice, if the rollup-plugin-visualizer would support this use-case: The plugin options could offer a hook that allows me to do something custom with the json data, instead of

  • unnecessarily writing or emitting a file
  • which is also for my case unne formatted with spaces due to the null, 2 arguments passed to JSON.stringify

IARI avatar Aug 09 '25 12:08 IARI

Hi, i do not think i will add this. Seems quite niche use case. I will rest this still open in case other people comment that it is common use case.

From my experience we just always archive folder with build results, including files like stats.json.

What you might use, instead of reading file in your custom plugin. Add emitFile: true to visualizer options. It will stop emitting file to fs directly and switch to rollup emit api, which will pass file in rollup pipeline. In this case you can catch emitted file in your plugin and get it directly. This will probably allow to do some simplification to your plugin

btd avatar Sep 03 '25 15:09 btd