Skip to content

Commit

Permalink
Enable responsive-loader for WebP/AVIF
Browse files Browse the repository at this point in the history
  • Loading branch information
tats-u committed Apr 21, 2023
1 parent 1f3d85e commit 6b06164
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/docusaurus-plugin-ideal-image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export default function pluginIdealImage(
return {};
}

const rulesRegex = new RegExp(
`\\.(?:png|jpe?g${options.enableWebpAvif ? '|webp|avif' : ''})$`,
'i',
);

return {
mergeStrategy: {
'module.rules': 'prepend',
},
module: {
rules: [
{
test: /\.(?:png|jpe?g)$/i,
test: rulesRegex,
use: [
require.resolve('@docusaurus/lqip-loader'),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ declare module '@docusaurus/plugin-ideal-image' {
* Tip: use network throttling in your browser to simulate slow networks.
*/
disableInDev?: boolean;
/**
* You can enable this plugin for WebP/AVIF images
* by setting this to `true`.
* Note: the default is `false` to keep backward compatibility.
*/
enableWebpAvif?: boolean;
};
}

Expand Down

0 comments on commit 6b06164

Please sign in to comment.