Registry / devops / webpack-inject-plugin

webpack-inject-plugin

JSON →
library1.5.5jsnpmunverified

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-plugin
INSTALL
IMPORT
SIG · WEBPACK-INJECT-PLU
W
webpack-inject-plugin
devopsjavascriptv1.5.5
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import InjectPlugin from 'webpack-inject-plugin'
✗ const InjectPlugin = require('webpack-inject-plugin')
The default export is the main plugin class. In CommonJS, you must use .default: const InjectPlugin = require('webpack-inject-plugin').default;
ENTRY_ORDER
✓ import { ENTRY_ORDER } from 'webpack-inject-plugin'
✗ import ENTRY_ORDER from 'webpack-inject-plugin'
ENTRY_ORDER is a named export, not the default. It provides constants First, Last, NotLast.
default (CommonJS)
✓ const InjectPlugin = require('webpack-inject-plugin').default
✗ const InjectPlugin = require('webpack-inject-plugin')
In CommonJS, the default export is accessed via .default because the package uses ESM-style exports.

Shows how to configure webpack-inject-plugin to inject console.log into the 'main' entry.

// webpack.config.js const InjectPlugin = require('webpack-inject-plugin').default; module.exports = { entry: './src/index.js', output: { filename: 'bundle.js' }, plugins: [ new InjectPlugin(() => { return "console.log('Injected code!');"; }, { entryName: 'main', entryOrder: require('webpack-inject-plugin').ENTRY_ORDER.Last }) ] };
Debug
Known issues
gotchaIn CommonJS, the default export is not the plugin constructor; you must use require('webpack-inject-plugin').default.
fix
Use const InjectPlugin = require('webpack-inject-plugin').default;
affects: >=1.0.0
deprecatedThe entryOrder option defaults to ENTRY_ORDER.NotLast. If you rely on the default, you may get unexpected bundle order.
fix
Explicitly set entryOrder to ENTRY_ORDER.First or ENTRY_ORDER.Last if you need exact control.
affects: >=1.0.0
gotchaThe injected code runs in the bundle's module scope, not the global scope unless you explicitly assign to window or global.
fix
To inject global code, wrap it in self-executing function or assign to globalThis.
affects: >=1.0.0
breakingIn v1.5.0, the loader ID handling changed. Multiple instances may conflict if IDs are not unique.
fix
Provide a unique loaderID option for each InjectPlugin instance if you use more than one.
affects: >=1.5.0
Errors
Common errors & fixes
TypeError: InjectPlugin is not a constructor
CommonJS require does not automatically resolve default export (ESM-style).
fix
Use const InjectPlugin = require('webpack-inject-plugin').default;
Module not found: Error: Can't resolve 'webpack-inject-plugin'
Missing installation or webpack version mismatch (requires webpack >=4.0.0).
fix
Run npm install webpack-inject-plugin --save-dev and ensure webpack is >=4.
Error: ENTRY_ORDER is not defined
Imported incorrectly; ENTRY_ORDER is a named export.
fix
Import with const { ENTRY_ORDER } = require('webpack-inject-plugin');
Upgrade
Version history
1.5.5latest on npm
Audit
Dependencies
webpackrequiredPeer dependency, plugin integrates with webpack's compilation process.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
webpack-inject-plugin — npm install webpack-inject-plugin · libregistry