add-asset-webpack-plugin

Dynamically add an asset to the Webpack graph

MIT 7 个版本
安装
npm install add-asset-webpack-plugin
yarn add add-asset-webpack-plugin
pnpm add add-asset-webpack-plugin
bun add add-asset-webpack-plugin
README

add-asset-webpack-plugin

Dynamically add an asset to the Webpack graph

Install

npm install add-asset-webpack-plugin

Usage

import AddAssetPlugin from 'add-asset-webpack-plugin';

export default {
	// …
	plugins: [
		new AddAssetPlugin('file.js', `
			console.log('This is a dynamically created file');
		`)
	]
};

API

AddAssetPlugin(filePath, source)

filePath

Type: string

Relative file path for the asset.

source

Type: string | (compilation => string | Promise<string>)

Asset source or a function that returns the asset source.

If a function, it will receive the compilation instance.

FAQ

Can I import the dynamically created files?

No. This plugin creates assets in the output directory, not importable modules. For virtual modules that can be imported, use webpack-virtual-modules instead.

版本列表
3.1.1 2025-09-13
3.1.0 2025-09-11
3.0.0 2024-04-30
2.0.1 2021-02-17
2.0.0 2020-11-11
1.0.0 2019-04-18
0.1.0 2017-12-07