A webpack plugin to dynamically inject arbitrary code into the bundle at build time. Current stable version is 1.5.5, compatible with webpack >=4.0.0. It allows injection via a loader function (synchronous or async), with options for entry filtering and ordering (First, Last, NotLast). Unlike other injection plugins, it leverages webpack's loader context and supports multiple plugin instances with unique loader IDs. Useful for polyfills, instrumentation, or config-driven code injection.
npm install webpack-inject-pluginVerified import paths — ran on the pinned version, not inferred.
Shows how to configure webpack-inject-plugin to inject console.log into the 'main' entry.
Use const InjectPlugin = require('webpack-inject-plugin').default;Explicitly set entryOrder to ENTRY_ORDER.First or ENTRY_ORDER.Last if you need exact control.
To inject global code, wrap it in self-executing function or assign to globalThis.
Provide a unique loaderID option for each InjectPlugin instance if you use more than one.
Use const InjectPlugin = require('webpack-inject-plugin').default;Run npm install webpack-inject-plugin --save-dev and ensure webpack is >=4.
Import with const { ENTRY_ORDER } = require('webpack-inject-plugin');