{"id":20136,"library":"inject-body-webpack-plugin","title":"inject-body-webpack-plugin","description":"A Webpack plugin (v1.3.0, latest) that injects a custom HTML string into the <body> of html-webpack-plugin output. Released under MIT, updated irregularly. Unlike generic string-replacement plugins, it integrates directly with html-webpack-plugin's compilation hooks, supporting position (start/end) and custom content. Requires html-webpack-plugin ^5.3.1 as a peer dependency. Ships TypeScript types for full IDE support.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jaid/inject-body-webpack-plugin","tags":["javascript","add-on","addon","html","html-webpack-plugin","html-webpack-plugin-plugin","library","node","node-js","typescript"],"install":[{"cmd":"npm install inject-body-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add inject-body-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add inject-body-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for hooking into HTML generation","package":"html-webpack-plugin","optional":false}],"imports":[{"note":"Default export only; named import will fail.","wrong":"import { InjectBodyPlugin } from 'inject-body-webpack-plugin'","symbol":"InjectBodyPlugin","correct":"import InjectBodyPlugin from 'inject-body-webpack-plugin'"},{"note":"CJS requires .default because module.exports is an ES module default export.","wrong":"const InjectBodyPlugin = require('inject-body-webpack-plugin')","symbol":"InjectBodyPlugin","correct":"const InjectBodyPlugin = require('inject-body-webpack-plugin').default"},{"note":"Options type is a named export; main class is default export.","wrong":"import { InjectBodyPluginOptions } from 'inject-body-webpack-plugin'","symbol":"InjectBodyPlugin","correct":"import type { InjectBodyPluginOptions } from 'inject-body-webpack-plugin'"}],"quickstart":{"code":"// webpack.config.js\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport InjectBodyPlugin from 'inject-body-webpack-plugin';\n\nexport default {\n  plugins: [\n    new HtmlWebpackPlugin({\n      templateContent: '<html><body></body></html>',\n    }),\n    new InjectBodyPlugin({\n      content: '<div id=\"root\">App</div>',\n      position: 'start',\n    }),\n  ],\n};","lang":"javascript","description":"Shows basic usage: import the plugin, instantiate with content string, and add to Webpack plugins array alongside HtmlWebpackPlugin."},"warnings":[{"fix":"Remove 'port' from options; it is no longer supported.","message":"Version 1.2.0 removed the 'port' option.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Ensure html-webpack-plugin version 4+ is installed.","message":"Version 1.1.0 migrated to html-webpack-plugin 4; incompatible with v3.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Default content changed in 1.3.0; specify 'content' explicitly for consistent behavior.","message":"Version 1.0.0 initial release; default content differs from later versions.","severity":"breaking","affected_versions":">=1.0.0 <1.3.0"},{"fix":"Order plugins so that HtmlWebpackPlugin appears first.","message":"Plugin must be placed after HtmlWebpackPlugin in the plugins array to function correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Sanitize any user-provided content before passing to the plugin.","message":"The injected content is raw HTML; no escaping. XSS risk if user input is used.","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 `import InjectBodyPlugin from 'inject-body-webpack-plugin'` (no braces).","cause":"Using named import instead of default import in ESM.","error":"TypeError: InjectBodyPlugin is not a constructor"},{"fix":"Run `npm install --save-dev html-webpack-plugin`.","cause":"Missing peer dependency html-webpack-plugin.","error":"Cannot find module 'html-webpack-plugin'"},{"fix":"Upgrade html-webpack-plugin to version 4 or higher.","cause":"Using incompatible html-webpack-plugin version (< 4).","error":"Error: Hook 'html-webpack-plugin-before-html-processing' is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}