{"id":20058,"library":"generate-file-webpack-plugin","title":"generate-file-webpack-plugin","description":"A general-purpose Webpack plugin (v1.0.1) for generating arbitrary files during the build process. Supports file paths (relative or absolute), content as strings, Buffers, Promises, or functions returning these. Works with Webpack 4.x (5.x untested) and Node.js 12+. Features include debug mode with console output. Less opinionated than similar plugins like `webpack-manifest-plugin` or `html-webpack-plugin`, allowing any file content generation. Last updated in 2020, currently in maintenance mode with no active development.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/kflGALORE/generate-file-webpack-plugin","tags":["javascript","webpack","plugin","webpack-plugin","generate","generator","file","files","create"],"install":[{"cmd":"npm install generate-file-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add generate-file-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add generate-file-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - works with Webpack 4.x (5.x untested)","package":"webpack","optional":false}],"imports":[{"note":"Package provides a CommonJS default export (function). There is no named export. Using ES import syntax fails in strict ESM contexts without a default export.","wrong":"import generate from 'generate-file-webpack-plugin'; // No default ESM export; use CJS require","symbol":"default","correct":"const generate = require('generate-file-webpack-plugin');"},{"note":"The named export 'GenerateFilePlugin' was added in v1.0.0 as the class name. The default export is the factory function. Both are functionally equivalent.","wrong":"const GenerateFilePlugin = require('generate-file-webpack-plugin'); // This gives the main function, not a class; wrong named export","symbol":"GenerateFilePlugin","correct":"const { GenerateFilePlugin } = require('generate-file-webpack-plugin');"},{"note":"Same as GenerateFilePlugin, but using the full name. Prefer the shorter GenerateFilePlugin.","wrong":"import { GenerateFileWebpackPlugin } from 'generate-file-webpack-plugin'; // No ESM export; use CJS destructuring","symbol":"GenerateFileWebpackPlugin","correct":"const { GenerateFileWebpackPlugin } = require('generate-file-webpack-plugin');"}],"quickstart":{"code":"const generate = require('generate-file-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: __dirname + '/dist',\n    filename: 'bundle.js'\n  },\n  plugins: [\n    generate({\n      file: 'version.json',\n      content: JSON.stringify({ version: '1.0.0', buildTime: Date.now() })\n    }),\n    generate({\n      file: 'about.txt',\n      content: () => `Built at ${new Date().toISOString()}`\n    })\n  ]\n};","lang":"javascript","description":"Demonstrates generating two files: a JSON file with version info and a text file with build timestamp using a function."},"warnings":[{"fix":"Use `generate(options)` directly without `new`.","message":"Do not use `new generate()` – it is a factory function, not a constructor. Using `new` will cause the plugin to be applied twice.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `const { GenerateFilePlugin } = require('generate-file-webpack-plugin');`.","message":"The named export `GenerateFileWebpackPlugin` is deprecated and will be removed in a future version. Use `GenerateFilePlugin` instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use absolute paths or ensure `output.path` is set correctly.","message":"Relative file paths are resolved relative to webpack's `output.path`, not the project root.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need compilation data, use a different plugin like `webpack-sources` or hook into compilation directly.","message":"The `content` option as a function receives no arguments; attempting to access `compilation` or other webpack internals will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `debug: false` in production builds.","message":"When using `debug: true`, the plugin logs to console via `console.log()`, which may interfere with CI log outputs.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `const generate = require('generate-file-webpack-plugin');`","cause":"Importing the package incorrectly, e.g., using `import generate from 'generate-file-webpack-plugin'` in an ESM context or using destructuring without default.","error":"TypeError: generate is not a function"},{"fix":"Remove the `new` keyword: `generate(options)`","cause":"Using `new generate(options)` instead of calling `generate(options)` as a factory function.","error":"Error: Plugin could not be instantiated. Did you use 'new' keyword?"},{"fix":"Run `npm install generate-file-webpack-plugin --save-dev`","cause":"Package not installed or missing from `package.json`.","error":"Module not found: Error: Can't resolve 'generate-file-webpack-plugin'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}