-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpPlugin.js
25 lines (23 loc) · 1005 Bytes
/
webpPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const webp = require('webp-converter');
const fs = require('fs');
//pass input image(.jpeg,.pnp .....) path ,output image(give path where to save and image file name with .webp extension)
//pass option(read documentation for options)
//cwebp(input,output,option)
class WebpConverterPlugin {
apply(compiler) {
compiler.hooks.initialize.tap('WebpConverterPlugin', () => {
console.log("start conversion");
const images = fs.readdirSync("assets");
images.forEach((dirname) => {
if (dirname.includes(".png") || dirname.includes(".jpg")) {
console.log("converting " + dirname);
const result = webp.cwebp("assets/" + dirname, "assets/" + dirname, "-q 80");
result.then((response) => {
console.log("done for" + dirname + ", response: ", response);
});
}
})
});
}
}
module.exports = WebpConverterPlugin;