Dynamically add an asset to the Webpack graph
Dynamically add an asset to the Webpack graph
Dynamically add an asset to the Webpack graph
npm install add-asset-webpack-pluginimport AddAssetPlugin from 'add-asset-webpack-plugin';
export default {
// …
plugins: [
new AddAssetPlugin('file.js', `
console.log('This is a dynamically created file');
`)
]
};Type: string
Relative file path for the asset.
Type: string | (compilation => string | Promise)
Asset source or a function that returns the asset source.
If a function, it will receive the compilation instance.
No. This plugin creates assets in the output directory, not importable modules. For virtual modules that can be imported, use webpack-virtual-modules instead.
NODE_ENV handlingmodule.exports for Babel and TypeScript compiled codeNo open issues yet, or sync has not completed.