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-pluginVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: instantiate plugin with file path and source string, then add to Webpack plugins array.
Use import (ESM) or switch to dynamic import with .default.
Upgrade Node.js to 18+ or stay on v2.x (supports Node >=10).
Use Webpack 5+ or stick with v1.x (supports Webpack 4).
Use webpack-virtual-modules if you need importable virtual files.
Use a unique relative path, e.g., 'assets/generated.js'.
Use import instead, or use dynamic import: const AddAssetPlugin = (await import('add-asset-webpack-plugin')).default;Use import AddAssetPlugin from 'add-asset-webpack-plugin'.
Use const { default: AddAssetPlugin } = require('add-asset-webpack-plugin'); or switch to dynamic import.No dependency data recorded yet.