https://github.com/peterroe/count-webpack-plugin
Count the number of chars in file.
https://github.com/peterroe/count-webpack-plugin
plugin webpack
Last synced: 11 months ago
JSON representation
Count the number of chars in file.
- Host: GitHub
- URL: https://github.com/peterroe/count-webpack-plugin
- Owner: peterroe
- Created: 2022-02-06T17:56:13.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T14:40:37.000Z (over 2 years ago)
- Last Synced: 2023-12-15T15:53:17.533Z (over 2 years ago)
- Topics: plugin, webpack
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## What is it?
A example of plugin of [`webpack`](https://webpack.js.org), and it's used to count the number of chars in file.
## Core Code
```js
class CountWebpackPlugin {
apply(compiler) {
compiler.hooks.emit.tap('CountWebpackPlugin', (
compilation
) => {
let str = ''
for (let filename in compilation.assets) {
const { _value } = compilation.assets[filename]
str += `Number of chars in \`${filename}\`: \`${_value.length}\` \n`
}
//write file
compilation.assets['fileSize.md'] = {
source() {
return str
}
}
})
}
}
module.exports = CountWebpackPlugin;
```