rollup-plugin-webpack-stats
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

rollup-plugin-webpack-stats

ci Socket Badge

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

// rollup.config.js
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';

export default {
  plugins: [
    // add it as the last plugin
    webpackStatsPlugin(),
  ],
};
// vite.config.js
import { defineConfig } from 'vite';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';

export default defineConfig((env) => ({
  plugins: [
    // Output webpack-stats.json file
    webpackStatsPlugin(),
  ],
}));

Options

  • fileName - JSON stats file inside rollup/vite output directory
  • excludeAssets - 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)>
  • transform - access and mutate the resulting stats after the conversion: (stats: WebpackStatsFilterd, sources: TransformSources, bundle: OutputBundle) => WebpackStatsFilterd

Examples

Output to a custom filename

// rollup.config.js
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';

module.exports = {
  plugins: [
    // add it as the last plugin
    webpackStatsPlugin({
      filename: 'artifacts/stats.json',
    }),
  ],
};

Exclude .map files

// rollup.config.js
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';

export default {
  plugins: [
    // add it as the last plugin
    webpackStatsPlugin({
      excludeAssets: /\.map$/,
    }),
  ],
};

Vite.js - multiple stats files when using plugin-legacy

// for the the modern and legacy outputs
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: [
          // Output webpack-stats-modern.json file for the modern build
          // Output webpack-stats-legacy.json file for the legacy build
          // Stats are an output plugin, as plugin-legacy works by injecting
          // an additional output, that duplicates the plugins configured here
          webpackStatsPlugin((options) => {
            const isLegacy = options.format === 'system';
            return {
              fileName: `webpack-stats${isLegacy ? '-legacy' : '-modern'}.json`,
            };
          }),
        ],
      },
    },
  },
  plugins: [
    legacy({
      /* Your legacy config here */
    }),
  ],
}));

Vite.js - update initial flag for chunks where the inital flag is incorrectly set to false

import { defineConfig } from 'vite';
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';

export default defineConfig((env) => ({
  build: {
    rollupOptions: {
      output: {
        plugins: [
          webpackStatsPlugin({
            transform: (stats) => {
              // Find the target chunk entry
              const mainChunkIndex = stats.chunks?.findIndex((chunk) => chunk.names?.includes("main"));

              // When the tartget chunk is found, set the initial flag to true
              if (typeof mainChunkIndex !== 'undefined' && stats?.chunks?.[mainChunkIndex]) {
                stats.chunks[mainChunkIndex] = {
                  ...stats.chunks[mainChunkIndex],
                  initial: true,
                };
              }

              // return the modified stats object
              return stats;
            },
          }),
        ],
      },
    },
  },
}));

Resources

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.3
4,730latest
1.2.4-beta.6
0beta

Version History

VersionDownloads (Last 7 Days)Published
1.2.4-beta.6
0
1.2.4-beta.5
42
1.2.4-beta.4
47
1.2.4-beta.3
49
1.2.4-beta.2
52
1.2.4-beta.1
50
1.2.3
4,730
1.2.3-beta.0
50
1.2.0-beta.1
3
1.2.0-beta.0
4
1.1.1
2,478
1.1.0
1,329
1.0.5
18
1.1.0-beta.0
1
1.0.5-beta.0
1
1.0.4
1
1.0.3
342
1.0.2
20
1.0.1
48
1.0.1-beta.2
1
1.0.1-beta.1
1
1.0.1-beta.0
1
1.0.0
1
1.0.0-beta.7
0
1.0.0-beta.6
1
1.0.0-beta.4
0
1.0.0-beta.3
0
1.0.0-beta.2
0
1.0.0-beta.1
0
0.4.1
23,168
1.0.0-beta.0
1
0.4.0
0
0.3.0
2
0.2.6
2,317
0.2.5
212
0.2.4
1,013
0.2.3
558
0.2.3-beta.0
0
0.2.2
56
0.2.2-beta.0
0
0.2.1
229
0.2.1-beta.1
0
0.2.04,396
0.1.07
0.0.47
0.0.37
0.0.27
0.0.17

Package Sidebar

Install

npm i rollup-plugin-webpack-stats

Weekly Downloads

41,257

Version

1.2.3

License

MIT

Unpacked Size

34.7 kB

Total Files

15

Last publish

Collaborators

  • vio
  • bundle-stats-bot
  • relativeci-bot