2.0.3 • Published 4 months ago

rollup-plugin-webpack-stats v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

rollup-plugin-webpack-stats

npm.io npm.io npm.io 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 - the JSON filepath relative to the build folder or absolute(default: webpack-stats.json)
  • transform - access and mutate the resulting stats after the conversion: (stats: WebpackStatsFilterd, sources: TransformSources, bundle: OutputBundle) => WebpackStatsFilterd
  • moduleOriginalSize - extract module original size or rendered size (default: false)
  • write - format and write the stats to disk(default: fs.write(filename, JSON.stringify(stats, null, 2)))
  • rollup stats options (rollup-plugin-stats)
    • 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)>

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

@relative-ci/agent examples

1.2.4-beta.5

6 months ago

1.2.4-beta.4

6 months ago

1.2.4-beta.6

6 months ago

1.2.4-beta.1

6 months ago

1.2.4-beta.3

6 months ago

1.2.4-beta.2

6 months ago

1.2.3

6 months ago

2.0.3

4 months ago

2.0.2

4 months ago

1.2.0-beta.1

7 months ago

1.2.0-beta.0

7 months ago

2.0.1-beta.0

5 months ago

2.0.1

5 months ago

2.0.0

5 months ago

2.0.0-beta.8

5 months ago

2.0.0-beta.7

5 months ago

1.2.3-beta.0

6 months ago

2.0.0-beta.2

5 months ago

2.0.0-beta.1

5 months ago

2.0.0-beta.0

5 months ago

2.0.0-beta.6

5 months ago

2.0.0-beta.5

5 months ago

2.0.0-beta.4

5 months ago

2.0.0-beta.3

5 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

10 months ago

1.0.5-beta.0

9 months ago

1.1.0-beta.0

9 months ago

1.0.2

10 months ago

1.0.1

12 months ago

1.0.0

1 year ago

1.0.1-beta.2

12 months ago

1.0.0-beta.2

1 year ago

1.0.1-beta.1

12 months ago

1.0.0-beta.3

1 year ago

1.0.1-beta.0

12 months ago

1.0.0-beta.4

1 year ago

1.0.0-beta.0

1 year ago

1.0.0-beta.1

1 year ago

0.3.0

1 year ago

1.0.0-beta.6

1 year ago

1.0.0-beta.7

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.3-beta.0

1 year ago

0.2.2-beta.0

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.1-beta.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago