{"id":15425,"library":"dumpmeta-webpack-plugin","title":"Webpack Dump Metadata Plugin","description":"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.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/drudv/dumpmeta-webpack-plugin","tags":["javascript","typescript"],"install":[{"cmd":"npm install dumpmeta-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add dumpmeta-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add dumpmeta-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Webpack plugin and requires Webpack as a peer dependency for its functionality.","package":"webpack","optional":false}],"imports":[{"note":"For CommonJS environments, use the named require syntax. For ESM, use the named import.","wrong":"const DumpMetaPlugin = require('dumpmeta-webpack-plugin');","symbol":"DumpMetaPlugin","correct":"import { DumpMetaPlugin } from 'dumpmeta-webpack-plugin';"},{"note":"This is the correct CommonJS syntax for importing the named export. Avoid default import as it's not a default export.","wrong":"import DumpMetaPlugin from 'dumpmeta-webpack-plugin';","symbol":"DumpMetaPlugin (CommonJS)","correct":"const { DumpMetaPlugin } = require('dumpmeta-webpack-plugin');"},{"note":"Used for type-checking the plugin's configuration options in TypeScript projects.","symbol":"DumpMetaPluginOptions","correct":"import type { DumpMetaPluginOptions } from 'dumpmeta-webpack-plugin';"}],"quickstart":{"code":"import { DumpMetaPlugin } from 'dumpmeta-webpack-plugin';\nimport path from 'path';\n\nexport default {\n  mode: 'production',\n  entry: './src/index.js',\n  output: {\n    filename: 'bundle.js',\n    path: path.resolve(__dirname, 'dist'),\n  },\n  plugins: [\n    // ... other webpack plugins ...\n    new DumpMetaPlugin({\n      filename: 'dist/meta.json', // Specify the output path for the metadata file\n      prepare: stats => ({\n        // Customize the metadata to save. Ensure data is JSON-serializable.\n        hash: stats.hash, // The build hash\n        version: stats.version, // Webpack version\n        buildTime: new Date().toISOString(), // Timestamp of the build\n        modulesCount: stats.compilation.modules.length, // Number of compiled modules\n        errors: stats.hasErrors(), // Check if the build had errors\n        warnings: stats.hasWarnings() // Check if the build had warnings\n      })\n    })\n  ]\n};","lang":"typescript","description":"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."},"warnings":[{"fix":"Review and update your `prepare` function logic when migrating to Webpack 5 to ensure it correctly extracts properties from the potentially changed `stats` object structure. Refer to Webpack 5's `stats` documentation.","message":"Version 0.2.0 introduced compatibility with Webpack 5. While the plugin itself aims to be backwards compatible, internal changes in Webpack's `stats` object structure between major versions might affect custom `prepare` functions written for older Webpack versions.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Ensure that the object returned by your `prepare` function contains only primitive values, arrays, and plain objects. Transform complex types (e.g., Dates) into serializable formats like ISO strings.","message":"The `prepare` option's return value *must* be JSON-serializable. If it returns functions, Promises, or other non-serializable JavaScript objects, the plugin will fail when attempting to write the file.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Install using `npm install dumpmeta-webpack-plugin --save-dev` or `yarn add dumpmeta-webpack-plugin --dev`.","message":"This plugin is typically a development dependency (`--save-dev`) as it operates during the build process and is not required at runtime in production bundles.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"For ES Modules, use `import { DumpMetaPlugin } from 'dumpmeta-webpack-plugin';`. For CommonJS, use `const { DumpMetaPlugin } = require('dumpmeta-webpack-plugin');`.","cause":"Attempting to import `DumpMetaPlugin` as a default export or incorrectly using `require`.","error":"TypeError: DumpMetaPlugin is not a constructor"},{"fix":"Carefully inspect the object returned by your `prepare` function. Ensure it does not include any properties that recursively refer back to themselves or parent objects. Only extract specific, necessary primitive properties.","cause":"The `prepare` function returned an object that contains circular references, which JSON.stringify cannot handle.","error":"Failed to serialize Webpack metadata: Converting circular structure to JSON"},{"fix":"Ensure that the directory where `meta.json` is to be written has appropriate write permissions for the user running the Webpack build. Alternatively, specify a different output `filename` to a writable location.","cause":"The plugin does not have sufficient write permissions to the specified `filename` path.","error":"WebpackError: [dumpmeta-webpack-plugin] Error writing metadata file: EACCES: permission denied, open '/path/to/meta.json'"}],"ecosystem":"npm"}