https://github.com/sindresorhus/add-asset-webpack-plugin
Dynamically add an asset to the Webpack graph
https://github.com/sindresorhus/add-asset-webpack-plugin
javascript nodejs npm-package webpack webpack-plugin
Last synced: 12 days ago
JSON representation
Dynamically add an asset to the Webpack graph
- Host: GitHub
- URL: https://github.com/sindresorhus/add-asset-webpack-plugin
- Owner: sindresorhus
- License: mit
- Created: 2017-12-07T02:42:30.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-04-30T09:57:51.000Z (12 months ago)
- Last Synced: 2025-03-30T08:11:12.346Z (19 days ago)
- Topics: javascript, nodejs, npm-package, webpack, webpack-plugin
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 97
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome - add-asset-webpack-plugin - Dynamically add an asset to the Webpack graph (JavaScript)
README
# add-asset-webpack-plugin
> Dynamically add an asset to the [Webpack](https://webpack.js.org) graph
## Install
```sh
npm install add-asset-webpack-plugin
```## Usage
```js
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)`
Asset source or a function that returns the asset source.
If a function, it will receive the [`compilation` instance](https://webpack.js.org/api/compilation/). And if the function returns a promise, it will be awaited.
## Related
- [node-env-webpack-plugin](https://github.com/sindresorhus/node-env-webpack-plugin) - Simplified `NODE_ENV` handling
- [add-module-exports-webpack-plugin](https://github.com/sindresorhus/add-module-exports-webpack-plugin) - Add `module.exports` for Babel and TypeScript compiled code