{"id":19379,"library":"base-href-webpack-plugin","title":"Base Href Webpack Plugin","description":"Webpack plugin (v3.0.1, stable) that extends html-webpack-plugin to programmatically insert or update the <base href=\"\" /> tag in the HTML head. Active release with support for Webpack 5 (v3.x), Webpack 4 (v2.x), and Webpack 3 (v1.x). Key differentiators: automatic base href injection without manual template editing; leaves template untouched if option omitted; ships TypeScript types. Alternatives typically require manual HTML template modification.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/dzonatan/base-href-webpack-plugin","tags":["javascript","base","href","webpack","plugin","typescript"],"install":[{"cmd":"npm install base-href-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add base-href-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add base-href-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: plugin requires html-webpack-plugin to operate","package":"html-webpack-plugin","optional":false},{"reason":"peer dependency: plugin is a webpack plugin","package":"webpack","optional":false}],"imports":[{"note":"Named export, not default. CommonJS require style. For ESM: import { BaseHrefWebpackPlugin } from 'base-href-webpack-plugin';","wrong":"const BaseHrefWebpackPlugin = require('base-href-webpack-plugin');","symbol":"BaseHrefWebpackPlugin","correct":"const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');"},{"note":"Plugin also has a default export. Named import is recommended for clarity.","wrong":"import { BaseHrefWebpackPlugin } from 'base-href-webpack-plugin';","symbol":"BaseHrefWebpackPlugin (default)","correct":"import BaseHrefWebpackPlugin from 'base-href-webpack-plugin';"},{"note":"TypeScript type for options object. Exported from package.","wrong":"","symbol":"BaseHrefWebpackPluginConfig","correct":"type BaseHrefWebpackPluginConfig = { baseHref: string }"}],"quickstart":{"code":"// webpack.config.js\nconst HtmlWebpackPlugin = require('html-webpack-plugin');\nconst { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');\n\nmodule.exports = {\n  plugins: [\n    new HtmlWebpackPlugin(),\n    new BaseHrefWebpackPlugin({ baseHref: '/' })\n  ]\n};","lang":"javascript","description":"Shows how to add BaseHrefWebpackPlugin to webpack config, requiring both html-webpack-plugin and the plugin itself."},"warnings":[{"fix":"Upgrade webpack to ^5.0.0 and html-webpack-plugin to ^4.0.0","message":"Version 3.x requires Webpack 5 and html-webpack-plugin ^4.0.0","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use v3.x for Webpack 5 or stay on v2.x for Webpack 4","message":"Version 2.x requires Webpack 4","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Always provide baseHref option to ensure the tag is inserted","message":"If baseHref option is not provided, the plugin silently does nothing - does not warn","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 { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin'); (named import)","cause":"Using default import or require incorrectly.","error":"TypeError: Cannot destructure property 'BaseHrefWebpackPlugin' of 'require(...)' as it is undefined."},{"fix":"Run npm install --save-dev html-webpack-plugin","cause":"html-webpack-plugin is a peer dependency and not installed.","error":"Error: Cannot find module 'html-webpack-plugin'"},{"fix":"Use v2.x for Webpack 4 or upgrade to Webpack 5","cause":"Using plugin v3 with Webpack 4 or earlier.","error":"Error: webpack.version is not defined - plugin requires webpack 5"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}