doesdev / rollup-plugin-analyzer

Mad metrics for your rollup bundles, know all the things

Home Page:http://rollup-plugin-analyzer.doesdev.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expose default reporting

FND opened this issue · comments

commented

Currently we have to decide between custom reporting via onAnalysis and rollup-plugin-analyzer's own (elaborate and useful) default reporting: Supplying the former disables the latter.

It would be helpful if the two weren't mutually exclusive so we could emit a summary while optionally also emitting the full report.

I imagine it might look something like this:

import { plugin as analyze, report } from 'rollup-plugin-analyzer'

    plugins: [analyze({onAnalysis})]

function onAnalysis(params) {
    console.error(`${params.bundleOrigSize}${params.bundleSize}`)

    if (FULL_REPORT) {
        console.error(report(params))
    }
}

So, I've done a couple things in this commit (will go out as 2.1.0 later). First I changed the behavior of onAnalysis so that it by default does not suppress the formatted output. In order to suppress it an option has been added skipFormatted. I think that's probably the cleanest solution and how onAnalysis should have been initially implemented.

I did also export the reporter as reporter, but I didn't document it as it's just an uglier way of accomplishing the same so I can't recommend it. The only case I could see it being useful is manipulating the analysis before sending it to the reporter, but can't think of any good reason to do that. Anyway, if you were to use it you would to call it with the analysisObject returned from onAnalysis as the first argument and the original options object as the second.

Sorry for the delay, hoped to have #1 fixed in this release as well, but that'll need to go in the next release. 2.1.0 is published.