rollup-plugin-webpack-stats
Generate rollup stats JSON file with a bundle-stats webpack supported structure.
Install
npm install --dev rollup-plugin-webpack-stats
or
yarn add --dev rollup-plugin-webpack-stats
or
pnpm add -D rollup-plugin-webpack-stats
Configure
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
export default {
plugins: [
webpackStatsPlugin(),
],
};
import { defineConfig } from 'vite';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
export default defineConfig((env) => ({
plugins: [
webpackStatsPlugin(),
],
}));
Options
fileName
- JSON stats file inside rollup/vite output directoryexcludeAssets
- exclude matching assets: string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>
excludeModules
- exclude matching modules: string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>
Examples
Output to a custom filename
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
module.exports = {
plugins: [
webpackStatsPlugin({
filename: 'artifacts/stats.json',
}),
],
};
Exclude .map
files
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
export default {
plugins: [
webpackStatsPlugin({
excludeAssets: /\.map$/,
}),
],
};
Vite.js - multiple stats files when using plugin-legacy
import { defineConfig } from 'vite';
import legacy from '@vitejs/plugin-legacy';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
export default defineConfig((env) => ({
build: {
rollupOptions: {
output: {
plugins: [
webpackStatsPlugin((options) => {
const isLegacy = options.format === 'system';
return {
fileName: `webpack-stats${isLegacy ? '-legacy' : '-modern'}.json`,
};
}),
],
},
},
},
plugins: [
legacy({
}),
],
}));
Resources