-
Notifications
You must be signed in to change notification settings - Fork 5
/
imagemin.config.js
80 lines (72 loc) · 2.2 KB
/
imagemin.config.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const path = require('node:path');
const weblog = require('webpack-log');
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
const ENV = require('./app.env');
const UTILS = require('./webpack.utils');
const imageminIgnore = UTILS.readIgnoreFile('./.imageminignore');
const imageminLogger = weblog({ name: 'imagemin' });
// https://sharp.pixelplumbing.com/api-output#gif
module.exports = {
implementation: ImageMinimizerPlugin.sharpMinify,
encodeOptions: {
jpeg: {
// https://sharp.pixelplumbing.com/api-output#jpeg
quality: 90,
effort: 1,
chromaSubsampling: '4:4:4',
},
png: {
// https://sharp.pixelplumbing.com/api-output#png
quality: 90,
effort: 1,
palette: false,
},
gif: {
// https://sharp.pixelplumbing.com/api-output#gif
quality: 90,
effort: 1,
},
},
};
module.exports.encodeOptions.jpg = module.exports.encodeOptions.jpeg;
module.exports.webp = {
quality: 95, // 0 - 100, or 100 for lossless
options: {
// https://sharp.pixelplumbing.com/api-output#webp
effort: 1,
chromaSubsampling: '4:4:4',
},
};
module.exports.avif = {
quality: 95, // 0 - 100, or 100 for lossless
options: {
// https://sharp.pixelplumbing.com/api-output#avif
effort: 1,
chromaSubsampling: '4:4:4',
},
};
module.exports.jpeg = {
quality: 90, // 0 - 100
options: {
// https://sharp.pixelplumbing.com/api-output#jpeg
effort: 1,
chromaSubsampling: '4:4:4',
},
};
module.exports.jpg = module.exports.jpeg;
module.exports.png = {
quality: 90, // 0 - 100, or 100 for lossless
options: {
// https://sharp.pixelplumbing.com/api-output#png
effort: 1,
palette: false,
},
};
module.exports.testIgnore = (filepath) => {
const relpath = UTILS.slash(path.relative(__dirname, path.normalize(filepath)));
const ignores = imageminIgnore.ignores(relpath);
if (ENV.DEBUG || ENV.ARGV.verbose) {
imageminLogger.info(`${JSON.stringify(relpath)} ${ignores ? 'ignores' : 'minified'}`);
}
return ignores;
};