Webpack Dump Metadata Plugin

0.2.0 · active · verified Tue Apr 21

The `dumpmeta-webpack-plugin` is a Webpack plugin designed to save build-time metadata to a specified file, typically for post-build analysis or integration with other tools. As of its current stable version, 0.2.0, it offers compatibility with Webpack 5. The plugin differentiates itself through its simplicity and a `prepare` option that allows developers to precisely extract and format the desired properties from Webpack's `stats` object before serialization, ensuring only relevant, JSON-serializable data is saved. While release cadence appears infrequent, updates address major Webpack version compatibility. It serves as a focused utility for build introspection rather than a comprehensive reporting tool.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and use `DumpMetaPlugin` in a `webpack.config.js` to save custom build metadata, including build hash and timestamps, to a `meta.json` file.

import { DumpMetaPlugin } from 'dumpmeta-webpack-plugin';
import path from 'path';

export default {
  mode: 'production',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  plugins: [
    // ... other webpack plugins ...
    new DumpMetaPlugin({
      filename: 'dist/meta.json', // Specify the output path for the metadata file
      prepare: stats => ({
        // Customize the metadata to save. Ensure data is JSON-serializable.
        hash: stats.hash, // The build hash
        version: stats.version, // Webpack version
        buildTime: new Date().toISOString(), // Timestamp of the build
        modulesCount: stats.compilation.modules.length, // Number of compiled modules
        errors: stats.hasErrors(), // Check if the build had errors
        warnings: stats.hasWarnings() // Check if the build had warnings
      })
    })
  ]
};

view raw JSON →