Skip to content

Commit 8f63330

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 269fafd commit 8f63330

7 files changed

Lines changed: 21 additions & 38 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({
@@ -101,6 +70,21 @@ module.exports = {
10170
]
10271

10372
if (mode === 'production') {
73+
plugins.push(
74+
new ImageMinimizerPlugin({
75+
minimizer: {
76+
implementation: ImageMinimizerPlugin.imageminMinify,
77+
options: {
78+
plugins: [
79+
['gifsicle', { interlaced: true }],
80+
['jpegtran', { progressive: true }],
81+
['optipng', { optimizationLevel: 5 }],
82+
['svgo', { svgoconfig }],
83+
],
84+
},
85+
},
86+
})
87+
)
10488
plugins.push(
10589
new BundleAnalyzerPlugin({
10690
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

β€Ž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;

0 commit comments

Comments
Β (0)