Registry / devops / add-asset-webpack-plugin

add-asset-webpack-plugin

JSON →
library3.1.1jsnpmunverified

Dynamically add an asset (file) to the Webpack output graph. This is a lightweight, zero-dependency Webpack plugin (v3.1.1) that lets you inject a file with a given source string, either statically or via a callback receiving the compilation object. It ships TypeScript types. Key differentiator: it only creates output assets, not virtual modules — use webpack-virtual-modules if you need importable modules. Supports Webpack >=5, Node >=18, ESM only. Maintained by Sindre Sorhus.

npm install add-asset-webpack-plugin
INSTALL
IMPORT
SIG · ADD-ASSET-WEBPACK-
A
add-asset-webpack-plugin
devopsjavascriptv3.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

AddAssetPlugin
import AddAssetPlugin from 'add-asset-webpack-plugin'
const AddAssetPlugin = require('add-asset-webpack-plugin')
ESM-only since v3; require() will fail with ERR_REQUIRE_ESM.
AddAssetPlugin (type)
import type AddAssetPlugin from 'add-asset-webpack-plugin'
import { AddAssetPlugin } from 'add-asset-webpack-plugin'
Type is default export; named import produces undefined.
AddAssetPlugin (default import with require)
const AddAssetPlugin = (await import('add-asset-webpack-plugin')).default
const AddAssetPlugin = require('add-asset-webpack-plugin').default
If you must use dynamic import, await the import and access .default. .default on require() gives undefined.

Shows basic usage: instantiate plugin with file path and source string, then add to Webpack plugins array.

import AddAssetPlugin from 'add-asset-webpack-plugin'; export default { plugins: [ new AddAssetPlugin('file.js', ` console.log('This is a dynamically created file'); `) ] };
Debug
Known issues
breakingv3.0.0 is ESM-only; require() throws ERR_REQUIRE_ESM.
fix
Use import (ESM) or switch to dynamic import with .default.
affects: >=3.0.0
breakingv3.0.0 requires Node.js >=18.
fix
Upgrade Node.js to 18+ or stay on v2.x (supports Node >=10).
affects: >=3.0.0
breakingv2.0.0 requires Webpack >=5.
fix
Use Webpack 5+ or stick with v1.x (supports Webpack 4).
affects: >=2.0.0
gotchaThis plugin creates output assets, not virtual modules; they cannot be imported by other modules during compilation.
fix
Use webpack-virtual-modules if you need importable virtual files.
affects: *
gotchaThe source is written to the output directory; ensure the filePath does not collide with other output files.
fix
Use a unique relative path, e.g., 'assets/generated.js'.
affects: *
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Trying to require() the ESM-only package.
fix
Use import instead, or use dynamic import: const AddAssetPlugin = (await import('add-asset-webpack-plugin')).default;
TypeError: AddAssetPlugin is not a constructor
Named import { AddAssetPlugin } instead of default import.
fix
Use import AddAssetPlugin from 'add-asset-webpack-plugin'.
AddAssetPlugin is not a constructor (when using require)
CommonJS require returns an object with a 'default' property, not the class itself.
fix
Use const { default: AddAssetPlugin } = require('add-asset-webpack-plugin'); or switch to dynamic import.
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
36
OpenAI (training)
1
Resources
add-asset-webpack-plugin — npm install add-asset-webpack-plugin · libregistry