Skip to content

Expose JS API to combine multiple outputs into one #188

Closed
@aklinker1

Description

@aklinker1

I'm working on a framework for building chrome extensions, WXT, that includes this plugin when running wxt build --analyze. Chrome extensions contain multiple bulid steps, so each step outputs a separate stats JSON file, and then the rollup-plugin-visualizer CLI is used to combine them.

However, this doesn't work out of the box when using pnpm and shamefully-hoist=true (the default). This is because the binary isn't included in node_modules/.bin, so it's not in the path. Instead, the binary is stored at node_modules/wxt/node_modules/.bin/rollup-plugin-visualizer. There might be a similar problem for yarn PnP, haven't tested it.

See wxt-dev/wxt#360 for more details.

I could add node_modules/wxt/node_modules/.bin to the path while calling spawn("rollup-plugin-visualizer") (and I likely will do that as a workaround for now), but I'd also like to just call a function instead of spawning a new process, something like this:

import { mergeStats } from 'rollup-plugin-visualizer';

await mergeStats({
  files: ["stats1.json", "stats2.json", ...],
  // other options...
});

After looking at the code, I think this is a pretty simple change. Just involves exporting runForPluginJson from plugin/index.ts, or another entrypoint if that doesn't make sense.

const runForPluginJson = async ({ title, template, filename, open }: CliArgs, files: string[]) => {

If that sounds OK, I'm willing to work on this and open a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions