rollup-plugin-webpack-stats
Version:
Rollup/Vite/Rolldown plugin to generate a stats JSON file with a bundle-stats webpack-compatible structure
50 lines (49 loc) • 2.15 kB
text/typescript
import { BundleTransformOptions } from "./transform.cjs";
import { StatsWrite } from "./write.cjs";
import { OutputBundle } from "rollup-plugin-stats";
import { StatsOptions } from "rollup-plugin-stats/extract";
//#region src/plugin.d.ts
/**
* A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,
* containing only the fields this plugin uses to generate a stats file for a specific output.
*/
type OutputOptions = {
/** Output directory for the generated files. */dir?: string | undefined; /** Output format */
format?: 'es' | 'esm' | 'module' | 'cjs' | 'commonjs' | 'iife' | 'umd' | 'amd' | 'system' | 'systemjs' | undefined;
};
/**
* Subset of the Vite/Rolldown/Rollup plugin hook context (`this`) used by this plugin.
*/
type PluginContext = {
/** Log an informational message through Vite/Rolldown/Rollup's logging pipeline. */info: (message: string) => void; /** Log a warning through Vite/Rolldown/Rollup's logging pipeline without stopping the build. */
warn: (message: string) => void;
};
/**
* Minimum plugin interface compatible with Vite/Rolldown/Rollup.
*/
type Plugin = {
/** Unique identifier for the plugin, used in error messages and logs. */name: string;
/**
* Hook called after the bundle has been fully generated but before it is
* written to disk. Receives the resolved output options and the complete
* output bundle map.
*/
generateBundle?: (this: PluginContext, outputOptions: OutputOptions, bundle: OutputBundle, isWrite: boolean) => void | Promise<void>;
};
type WebpackStatsOptions = {
/**
* JSON file output fileName
* default: webpack-stats.json
*/
fileName?: string;
/**
* Custom file writer
* @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));
*/
write?: StatsWrite;
} & Omit<StatsOptions, 'source' | 'map'> & BundleTransformOptions;
type WebpackStatsOptionsOrBuilder = WebpackStatsOptions | ((outputOptions: OutputOptions) => WebpackStatsOptions);
declare const webpackStats: (options?: WebpackStatsOptionsOrBuilder) => Plugin;
//#endregion
export { webpackStats };
//# sourceMappingURL=plugin.d.cts.map