Registry / devops / generate-file-webpack-plugin

generate-file-webpack-plugin

JSON →
library1.0.1jsnpmunverified

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.

npm install generate-file-webpack-plugin
INSTALL
IMPORT
SIG · GENERATE-FILE-WEBP
G
generate-file-webpack-plugin
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const generate = require('generate-file-webpack-plugin');
import generate from 'generate-file-webpack-plugin'; // No default ESM export; use CJS require
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.
GenerateFilePlugin
const { GenerateFilePlugin } = require('generate-file-webpack-plugin');
const GenerateFilePlugin = require('generate-file-webpack-plugin'); // This gives the main function, not a class; wrong named export
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.
GenerateFileWebpackPlugin
const { GenerateFileWebpackPlugin } = require('generate-file-webpack-plugin');
import { GenerateFileWebpackPlugin } from 'generate-file-webpack-plugin'; // No ESM export; use CJS destructuring
Same as GenerateFilePlugin, but using the full name. Prefer the shorter GenerateFilePlugin.

Demonstrates generating two files: a JSON file with version info and a text file with build timestamp using a function.

const generate = require('generate-file-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: __dirname + '/dist', filename: 'bundle.js' }, plugins: [ generate({ file: 'version.json', content: JSON.stringify({ version: '1.0.0', buildTime: Date.now() }) }), generate({ file: 'about.txt', content: () => `Built at ${new Date().toISOString()}` }) ] };
Debug
Known issues
gotchaDo not use `new generate()` – it is a factory function, not a constructor. Using `new` will cause the plugin to be applied twice.
fix
Use `generate(options)` directly without `new`.
affects: >=1.0.0
deprecatedThe named export `GenerateFileWebpackPlugin` is deprecated and will be removed in a future version. Use `GenerateFilePlugin` instead.
fix
Use `const { GenerateFilePlugin } = require('generate-file-webpack-plugin');`.
affects: >=1.0.0
gotchaRelative file paths are resolved relative to webpack's `output.path`, not the project root.
fix
Use absolute paths or ensure `output.path` is set correctly.
affects: >=1.0.0
gotchaThe `content` option as a function receives no arguments; attempting to access `compilation` or other webpack internals will fail.
fix
If you need compilation data, use a different plugin like `webpack-sources` or hook into compilation directly.
affects: >=1.0.0
gotchaWhen using `debug: true`, the plugin logs to console via `console.log()`, which may interfere with CI log outputs.
fix
Set `debug: false` in production builds.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: generate is not a function
Importing the package incorrectly, e.g., using `import generate from 'generate-file-webpack-plugin'` in an ESM context or using destructuring without default.
fix
Use `const generate = require('generate-file-webpack-plugin');`
Error: Plugin could not be instantiated. Did you use 'new' keyword?
Using `new generate(options)` instead of calling `generate(options)` as a factory function.
fix
Remove the `new` keyword: `generate(options)`
Module not found: Error: Can't resolve 'generate-file-webpack-plugin'
Package not installed or missing from `package.json`.
fix
Run `npm install generate-file-webpack-plugin --save-dev`
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
webpackrequiredPeer dependency - works with Webpack 4.x (5.x untested)
Agent activity
2 hits · last 30 days
node
2
Resources
generate-file-webpack-plugin — npm install generate-file-webpack-plugin · libregistry