add-asset-webpack-plugin
v3.1.1
Published
Dynamically add an asset to the Webpack graph
Downloads
19,991
Maintainers
Readme
add-asset-webpack-plugin
Dynamically add an asset to the Webpack graph
Install
npm install add-asset-webpack-pluginUsage
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.
Related
- node-env-webpack-plugin - Simplified
NODE_ENVhandling - add-module-exports-webpack-plugin - Add
module.exportsfor Babel and TypeScript compiled code
