https://github.com/knuton/transform-assets-webpack-plugin
A configurable plugin for applying asset transformations in Webpack.
https://github.com/knuton/transform-assets-webpack-plugin
assets webpack webpack-plugin
Last synced: about 2 months ago
JSON representation
A configurable plugin for applying asset transformations in Webpack.
- Host: GitHub
- URL: https://github.com/knuton/transform-assets-webpack-plugin
- Owner: knuton
- License: mit
- Created: 2017-10-27T09:14:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-27T13:24:29.000Z (over 8 years ago)
- Last Synced: 2025-10-01T13:24:28.574Z (9 months ago)
- Topics: assets, webpack, webpack-plugin
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# transform-assets-webpack-plugin
A configurable plugin for applying asset transformations in Webpack.
## Installation
npm install transform-assets-webpack-plugin
## Example
This example removes all `a` characters from `.txt` assets.
```js
const TransformAssetsPlugin = require('transform-assets-webpack-plugin')
module.exports = {
plugins: [
new TransformAssetsPlugin({
transformations: [
{
test: /\.txt$/,
transform: (buff) => Promise.resolve(
Buffer.from(buff.toString('utf8').replace(/a/g, ''))
)
}
]
})
]
}
```
## API
### new TransformAssetsPlugin(options)
#### options.disable
**type**: `boolean`
**default**: `false`
When set to `true` the plugin will not do anything. This is useful
for disabling transformations during development, and only performing
them in production.
#### options.maxConcurrency
**type**: `number`
**default**: The number of logical CPUs on the system
Sets the maximum of concurrent asset processing workers.
#### options.transformations
**type**: `Array<{ test: Function|RegExp, transform: Function }>`
**default**: `[]`
An array of transformations that will be applied to each asset, in
order.
Each transformation is an object with a `test` and `transform` property.
`test` is either a regular expression or a function taking a `string`
pathname and returning a `boolean`. If the test is positive, the
transformation will be applied to the asset's contents. `transform`
needs to accept and return a `Promise`.
## Acknowledgments
Inspired by Gregory Brenner's
[imagemin-webpack-plugin](https://github.com/Klathmon/imagemin-webpack-plugin).
I simply removed most features to make it a general asset transformation
utility.
## Copyright/License
(C) Johannes Emerich 2017
MIT License