Skip to content

Commit 0a61e3b

Browse files
committed
refactor: remove JPEG images and update to WebP format
- Deleted unused JPEG images (default.jpg, logo.jpg) and replaced them with WebP versions (default.webp, logo.webp). - Updated SCSS and Webpack configuration to reference the new WebP images. - Removed imagemin-webp from package.json and yarn.lock as it is no longer needed. - Generate default images in webp format by default
1 parent 90876fc commit 0a61e3b

9 files changed

Lines changed: 24 additions & 75 deletions

File tree

config/plugins.js

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,7 @@ const WebpackStaticImagesPlugin = require('./webpack-static-images-plugin')
1818

1919
module.exports = {
2020
get: function (mode) {
21-
const isProduction = mode === 'production'
22-
// A single instance: `optimization.minimizer` is only `apply()`'d when `minimize: true`
23-
// (see webpack `WebpackOptionsApply.js`), so WebP `?as=webp` must live on the main
24-
// `plugins` list to work with `yarn start` / dev. Image minify runs on `processAssets`
25-
// from this same plugin in production only (keeps dev watch fast).
26-
const imageMinimizerOptions = {
27-
loader: true,
28-
generator: [
29-
{
30-
preset: 'webp',
31-
implementation: ImageMinimizerPlugin.imageminGenerate,
32-
options: {
33-
plugins: ['imagemin-webp'],
34-
},
35-
},
36-
],
37-
}
38-
if (isProduction) {
39-
imageMinimizerOptions.minimizer = {
40-
implementation: ImageMinimizerPlugin.imageminMinify,
41-
options: {
42-
plugins: [
43-
['gifsicle', { interlaced: true }],
44-
['jpegtran', { progressive: true }],
45-
['optipng', { optimizationLevel: 5 }],
46-
['svgo', { svgoconfig }],
47-
],
48-
},
49-
}
50-
}
5121
const plugins = [
52-
new ImageMinimizerPlugin(imageMinimizerOptions),
5322
new WebpackThemeJsonPlugin({
5423
watch: mode !== 'production',
5524
}),
@@ -81,9 +50,9 @@ module.exports = {
8150
outputImageLocations: 'image-locations.json', // Output locations file name
8251
outputImageSizes: 'image-sizes.json', // Output sizes file name
8352
generateDefaultImages: true, // Generate default images
84-
defaultImageSource: 'src/img/static/default.jpg', // Source image for generation
53+
defaultImageSource: 'src/img/static/default.webp', // Source image for generation
8554
defaultImagesOutputDir: 'dist/images', // Default images output directory
86-
defaultImageFormat: 'jpg', // Generated image format (jpg, png, webp, avif)
55+
defaultImageFormat: 'webp', // Generated image format (jpg, png, webp, avif)
8756
silence: true, // Suppress console output
8857
}),
8958
new WebpackStaticImagesPlugin({
@@ -95,6 +64,21 @@ module.exports = {
9564
]
9665

9766
if (mode === 'production') {
67+
plugins.push(
68+
new ImageMinimizerPlugin({
69+
minimizer: {
70+
implementation: ImageMinimizerPlugin.imageminMinify,
71+
options: {
72+
plugins: [
73+
['gifsicle', { interlaced: true }],
74+
['jpegtran', { progressive: true }],
75+
['optipng', { optimizationLevel: 5 }],
76+
['svgo', { svgoconfig }],
77+
],
78+
},
79+
},
80+
})
81+
)
9882
plugins.push(
9983
new BundleAnalyzerPlugin({
10084
analyzerMode: 'json',

config/webpack-image-sizes-plugin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class WebpackImageSizesPlugin {
4141
outputImageLocations: 'image-locations.json',
4242
outputImageSizes: 'image-sizes.json',
4343
generateDefaultImages: false,
44-
defaultImageSource: 'src/img/static/default.jpg',
44+
defaultImageSource: 'src/img/static/default.webp',
4545
defaultImagesOutputDir: 'dist/images',
46-
defaultImageFormat: 'jpg',
46+
defaultImageFormat: 'webp',
4747
silence: false,
4848
...options,
4949
}
@@ -543,8 +543,7 @@ class WebpackImageSizesPlugin {
543543

544544
this.log(
545545
'log',
546-
`🖼️ Processing ${sizeKeys.length} default images (${format.toUpperCase()}) from ${
547-
this.options.defaultImageSource
546+
`🖼️ Processing ${sizeKeys.length} default images (${format.toUpperCase()}) from ${this.options.defaultImageSource
548547
}`
549548
)
550549

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"imagemin-jpegtran": "^7.0.0",
4444
"imagemin-optipng": "^8.0.0",
4545
"imagemin-svgo": "^10.0.1",
46-
"imagemin-webp": "^8.0.0",
4746
"mini-css-extract-plugin": "^1.5.0",
4847
"postcss": "^8.4.24",
4948
"postcss-import": "^15.1.0",

src/img/static/default.jpg

-6.58 KB
Binary file not shown.

src/img/static/default.webp

3.84 KB
Loading

src/img/static/logo.jpg

-6.58 KB
Binary file not shown.

src/img/static/logo.webp

3.84 KB
Loading

src/scss/login.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SCSS variables to customise the login page styles
22
// The CSS file generated in dist/ by webpack is called automatically thanks to the WP Login Page mu-plugin present in the WP Skeleton.
33

4-
$login-logo-path: "../../src/img/static/logo.jpg?as=webp";
4+
$login-logo-path: "../../src/img/static/logo.webp";
55
$login-logo-size: 312px 43px;
66
$login-logo-height: 60px;
77
$login-body-bg-color: #666;

yarn.lock

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,6 @@ __metadata:
22802280
imagemin-jpegtran: "npm:^7.0.0"
22812281
imagemin-optipng: "npm:^8.0.0"
22822282
imagemin-svgo: "npm:^10.0.1"
2283-
imagemin-webp: "npm:^8.0.0"
22842283
lazysizes: "npm:^5.3.2"
22852284
mini-css-extract-plugin: "npm:^1.5.0"
22862285
oneloop.js: "npm:^5.2.1"
@@ -2364,7 +2363,7 @@ __metadata:
23642363
languageName: node
23652364
linkType: hard
23662365

2367-
"bin-wrapper@npm:^4.0.0, bin-wrapper@npm:^4.0.1":
2366+
"bin-wrapper@npm:^4.0.0":
23682367
version: 4.1.0
23692368
resolution: "bin-wrapper@npm:4.1.0"
23702369
dependencies:
@@ -3384,18 +3383,6 @@ __metadata:
33843383
languageName: node
33853384
linkType: hard
33863385

3387-
"cwebp-bin@npm:^8.0.0":
3388-
version: 8.0.0
3389-
resolution: "cwebp-bin@npm:8.0.0"
3390-
dependencies:
3391-
bin-build: "npm:^3.0.0"
3392-
bin-wrapper: "npm:^4.0.1"
3393-
bin:
3394-
cwebp: cli.js
3395-
checksum: 10/cdf14da37bcc225a5ec577955ad32dfc97469f574af37520030d4da8858e74b9433e8dca5f892041f88f8e19554cdbdc94851afde1e0f22271308f0dd270e767
3396-
languageName: node
3397-
linkType: hard
3398-
33993386
"data-view-buffer@npm:^1.0.2":
34003387
version: 1.0.2
34013388
resolution: "data-view-buffer@npm:1.0.2"
@@ -4474,7 +4461,7 @@ __metadata:
44744461
languageName: node
44754462
linkType: hard
44764463

4477-
"exec-buffer@npm:^3.0.0, exec-buffer@npm:^3.2.0":
4464+
"exec-buffer@npm:^3.0.0":
44784465
version: 3.2.0
44794466
resolution: "exec-buffer@npm:3.2.0"
44804467
dependencies:
@@ -4741,7 +4728,7 @@ __metadata:
47414728
languageName: node
47424729
linkType: hard
47434730

4744-
"file-type@npm:^10.4.0, file-type@npm:^10.5.0":
4731+
"file-type@npm:^10.4.0":
47454732
version: 10.11.0
47464733
resolution: "file-type@npm:10.11.0"
47474734
checksum: 10/787ab64574316dbd423eccbadac2876879c5d2f1d24309948debdaf1dfbd0f5f25f881a716f44d294090bf435407f6938da41c833895c888a78127113337a608
@@ -5792,17 +5779,6 @@ __metadata:
57925779
languageName: node
57935780
linkType: hard
57945781

5795-
"imagemin-webp@npm:^8.0.0":
5796-
version: 8.0.0
5797-
resolution: "imagemin-webp@npm:8.0.0"
5798-
dependencies:
5799-
cwebp-bin: "npm:^8.0.0"
5800-
exec-buffer: "npm:^3.2.0"
5801-
is-cwebp-readable: "npm:^3.0.0"
5802-
checksum: 10/707404df20f346b83b5651bc99017c2f272f400b87238ed64236a0dce112dd9c5d77d10ab365af6356e6ce33afd6a2d79fe534c82a8717ea746d9bc6f70b6804
5803-
languageName: node
5804-
linkType: hard
5805-
58065782
"imagemin@npm:^8.0.1":
58075783
version: 8.0.1
58085784
resolution: "imagemin@npm:8.0.1"
@@ -6045,15 +6021,6 @@ __metadata:
60456021
languageName: node
60466022
linkType: hard
60476023

6048-
"is-cwebp-readable@npm:^3.0.0":
6049-
version: 3.0.0
6050-
resolution: "is-cwebp-readable@npm:3.0.0"
6051-
dependencies:
6052-
file-type: "npm:^10.5.0"
6053-
checksum: 10/768ae017586ba2fb0831d3cc9cfb4cd56c9580b71684ea5584cf61910597c5fe91a419490ed85422424c6339fe9c327df3643c3496145134d4d0385fb479b591
6054-
languageName: node
6055-
linkType: hard
6056-
60576024
"is-data-descriptor@npm:^1.0.1":
60586025
version: 1.0.1
60596026
resolution: "is-data-descriptor@npm:1.0.1"

0 commit comments

Comments
 (0)