Skip to content

Commit 27a484a

Browse files
committed
doc: updated documentation for prefer-ideal-image
1 parent f06cabf commit 27a484a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

website/docs/api/misc/eslint-plugin/README.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ For more fine-grained control, you can also enable the plugin manually and confi
5454
| [`@docusaurus/string-literal-i18n-messages`](./string-literal-i18n-messages.mdx) | Enforce translate APIs to be called on plain text labels ||
5555
| [`@docusaurus/no-html-links`](./no-html-links.mdx) | Ensures @docusaurus/Link is used instead of `<a>` tags ||
5656
| [`@docusaurus/prefer-docusaurus-heading`](./prefer-docusaurus-heading.mdx) | Ensures @theme/Heading is used instead of `<hn>` tags for headings ||
57+
| [`@docusaurus/prefer-ideal-image`](./prefer-ideal-image.mdx) | Ensures @theme/IdealImage is used instead of `<img>` tags for embedding images | |
5758

5859
✅ = recommended
5960

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
slug: /api/misc/@docusaurus/eslint-plugin/prefer-ideal-image
3+
---
4+
5+
# prefer-ideal-image
6+
7+
Ensure that the `<IdealImage />` component provided by the [`@docusaurus/plugin-ideal-image`](../../plugins/plugin-ideal-image.mdx) plugin is used instead of standard `<img>` tags for local assets.
8+
9+
The `@theme/IdealImage` component automatically generates responsive images, provides lazy-loading, and adds low-quality image placeholders (LQIP) to improve LCP and user experience.
10+
11+
## Rule Details {#details}
12+
13+
This rule flags standard HTML `<img>` tags that point to local files, suggesting the use of `IdealImage` for better optimization.
14+
15+
Examples of **incorrect** code for this rule:
16+
17+
```jsx
18+
// Error: Definitely a local image via require()
19+
<img src={require('./thumbnail.png')} />
20+
21+
// Warning: Likely a local image via relative path
22+
<img src="./img/logo.png" />
23+
24+
// Warning: Root-relative path usually points to the static folder
25+
<img src="/img/hero.jpg" />
26+
```
27+
28+
Examples of **correct** code for this rule:
29+
30+
```jsx
31+
// Optimized using the IdealImage component
32+
import IdealImage from '@theme/IdealImage';
33+
34+
<IdealImage img={require('./thumbnail.png')} />
35+
36+
// External images are ignored
37+
<img src="[https://example.com/external.png](https://example.com/external.png)" />
38+
39+
// SVGs are ignored as IdealImage does not support them
40+
<img src="./icon.svg" />
41+
```
42+
43+
## When to not use it
44+
45+
If you have not installed or do not plan to use @docusaurus/plugin-ideal-image, you should keep this rule disabled.
46+
47+
## Further Reading {#further-reading}
48+
49+
- https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-ideal-image
50+
- https://web.dev/articles/browser-level-image-lazy-loading

0 commit comments

Comments
 (0)