{"id":20057,"library":"generate-asset-webpack-plugin","title":"Generate Asset Webpack Plugin","description":"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.","status":"maintenance","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/kjbekkelund/generate-asset-webpack-plugin","tags":["javascript","webpack","plugin","asset","index.html"],"install":[{"cmd":"npm install generate-asset-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add generate-asset-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add generate-asset-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin is designed to work as a Webpack plugin","package":"webpack","optional":false}],"imports":[{"note":"Package uses CommonJS; ESM import not supported.","wrong":"import GenerateAssetPlugin from 'generate-asset-webpack-plugin';","symbol":"GenerateAssetPlugin","correct":"const GenerateAssetPlugin = require('generate-asset-webpack-plugin');"},{"note":"Default export only; named destructuring fails.","wrong":"const { GenerateAssetPlugin } = require('generate-asset-webpack-plugin');","symbol":"default","correct":"const GenerateAssetPlugin = require('generate-asset-webpack-plugin');"},{"note":"Constructor expects an options object, not separate arguments.","wrong":"new GenerateAssetPlugin('file.txt', (compilation, cb) => cb(null, 'content'))","symbol":"new GenerateAssetPlugin({...})","correct":"new GenerateAssetPlugin({ filename: 'file.txt', fn: (compilation, cb) => cb(null, 'content') })"}],"quickstart":{"code":"const GenerateAssetPlugin = require('generate-asset-webpack-plugin');\nconst webpack = require('webpack');\n\nconst compiler = webpack({\n  entry: './src/index.js',\n  output: { path: './dist', filename: 'bundle.js' },\n  plugins: [\n    new GenerateAssetPlugin({\n      filename: 'index.html',\n      fn: (compilation, cb) => {\n        const chunk = compilation.chunks[0];\n        const jsFile = chunk.files[0];\n        const html = `<!DOCTYPE html><html><head><title>App</title></head><body><script src=\"${jsFile}\"></script></body></html>`;\n        cb(null, html);\n      },\n      extraFiles: ['favicon.ico']\n    })\n  ]\n});\n\ncompiler.run((err, stats) => {\n  if (err) console.error(err);\n  console.log(stats.toString({ colors: true }));\n});","lang":"javascript","description":"Shows creating a Webpack config that generates an index.html as an asset, using the plugin's callback API."},"warnings":[{"fix":"Use html-webpack-plugin or another plugin compatible with Webpack 4+.","message":"Webpack 4+ no longer supports plugins using old compilation hooks; this plugin does not work with Webpack 4+.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Always invoke cb(null, content) or cb(error) in the fn callback.","message":"cb must be called exactly once; failure to call cb will hang the build.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure extraFiles entries are already present in the compilation or use another plugin to add them.","message":"extraFiles is not well documented; files listed must exist in compilation.assets or they will be ignored.","severity":"gotcha","affected_versions":">=0.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 GenerateAssetPlugin = require('generate-asset-webpack-plugin');","cause":"Incorrect import: destructured instead of default require.","error":"TypeError: GenerateAssetPlugin is not a constructor"},{"fix":"Run npm install --save-dev generate-asset-webpack-plugin and check node_modules.","cause":"Package not installed or typo in package name.","error":"Error: Cannot find module 'generate-asset-webpack-plugin'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}