Skip to content

Commit 0edc239

Browse files
committed
Enable responsive-loader for WebP/AVIF
1 parent 9c3f619 commit 0edc239

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/docusaurus-plugin-ideal-image/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ export default function pluginIdealImage(
4646
return {};
4747
}
4848

49+
const rulesRegex = new RegExp(
50+
`\\.(?:png|jpe?g${options.enableWebpAvif ? '|webp|avif' : ''})$`,
51+
'i',
52+
);
53+
4954
return {
5055
mergeStrategy: {
5156
'module.rules': 'prepend',
5257
},
5358
module: {
5459
rules: [
5560
{
56-
test: /\.(?:png|jpe?g)$/i,
61+
test: rulesRegex,
5762
use: [
5863
require.resolve('@docusaurus/lqip-loader'),
5964
{

packages/docusaurus-plugin-ideal-image/src/plugin-ideal-image.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ declare module '@docusaurus/plugin-ideal-image' {
4646
* Tip: use network throttling in your browser to simulate slow networks.
4747
*/
4848
disableInDev?: boolean;
49+
/**
50+
* You can enable this plugin for WebP/AVIF images
51+
* by setting this to `true`.
52+
* Note: the default is `false` to keep backward compatibility.
53+
*/
54+
enableWebpAvif?: boolean;
4955
};
5056
}
5157

0 commit comments

Comments
 (0)