Registry / web-framework / generate-asset-webpack-plugin

generate-asset-webpack-plugin

JSON →
library0.3.0jsnpmunverified

Webpack plugin (v0.3.0) for dynamically generating asset files (like index.html) during compilation, with access to compilation info. Lightweight alternative to html-webpack-plugin with a callback-based API. Released 2015, no recent updates; works with Webpack 1-3 but not v4+. Suitable for simple HTML generation without templating.

npm install generate-asset-webpack-plugin
INSTALL
IMPORT
SIG · GENERATE-ASSET-WEB
G
generate-asset-webpack-plugin
web-frameworkjavascriptv0.3.0
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.

GenerateAssetPlugin
const GenerateAssetPlugin = require('generate-asset-webpack-plugin');
import GenerateAssetPlugin from 'generate-asset-webpack-plugin';
Package uses CommonJS; ESM import not supported.
default
const GenerateAssetPlugin = require('generate-asset-webpack-plugin');
const { GenerateAssetPlugin } = require('generate-asset-webpack-plugin');
Default export only; named destructuring fails.
new GenerateAssetPlugin({...})
new GenerateAssetPlugin({ filename: 'file.txt', fn: (compilation, cb) => cb(null, 'content') })
new GenerateAssetPlugin('file.txt', (compilation, cb) => cb(null, 'content'))
Constructor expects an options object, not separate arguments.

Shows creating a Webpack config that generates an index.html as an asset, using the plugin's callback API.

const GenerateAssetPlugin = require('generate-asset-webpack-plugin'); const webpack = require('webpack'); const compiler = webpack({ entry: './src/index.js', output: { path: './dist', filename: 'bundle.js' }, plugins: [ new GenerateAssetPlugin({ filename: 'index.html', fn: (compilation, cb) => { const chunk = compilation.chunks[0]; const jsFile = chunk.files[0]; const html = `<!DOCTYPE html><html><head><title>App</title></head><body><script src="${jsFile}"></script></body></html>`; cb(null, html); }, extraFiles: ['favicon.ico'] }) ] }); compiler.run((err, stats) => { if (err) console.error(err); console.log(stats.toString({ colors: true })); });
Debug
Known issues
breakingWebpack 4+ no longer supports plugins using old compilation hooks; this plugin does not work with Webpack 4+.
fix
Use html-webpack-plugin or another plugin compatible with Webpack 4+.
affects: >=0.3.0
gotchacb must be called exactly once; failure to call cb will hang the build.
fix
Always invoke cb(null, content) or cb(error) in the fn callback.
affects: >=0.0.0
gotchaextraFiles is not well documented; files listed must exist in compilation.assets or they will be ignored.
fix
Ensure extraFiles entries are already present in the compilation or use another plugin to add them.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: GenerateAssetPlugin is not a constructor
Incorrect import: destructured instead of default require.
fix
Use const GenerateAssetPlugin = require('generate-asset-webpack-plugin');
Error: Cannot find module 'generate-asset-webpack-plugin'
Package not installed or typo in package name.
fix
Run npm install --save-dev generate-asset-webpack-plugin and check node_modules.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency; plugin is designed to work as a Webpack plugin
Agent activity
4 hits · last 30 days
node
4
Resources
generate-asset-webpack-plugin — npm install generate-asset-webpack-plugin · libregistry