You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b48d35a
Browse filesBrowse the repository at this point in the historyBrowse files
| Placeholder for a missing image |[Image Fallback](/plugins/image-fallback)|`vite.plugins`|
49
+
| Placeholder for a missing image |[Image Fallback](/plugins/image-fallback)|`vite.plugins`, plus the theme|
50
50
51
51
## The config
52
52
53
53
<<< @/.vitepress/config.mts{ts}
54
54
55
55
## The theme
56
56
57
-
The theme registers the badge component and loads its stylesheet, and turns on the three popovers: glossary definitions, the HTML Escape hints that explain broken markup, and the Broken Links hints that explain dead links:
57
+
The theme registers the badge component and loads its stylesheet, and turns on the four popovers: glossary definitions, the HTML Escape hints that explain broken markup, the Broken Links hints that explain dead links, and the Image Fallback hints that explain missing images:
Copy file name to clipboardExpand all lines: docs/plugins/image-fallback.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,13 @@ The image below points at a file that does not exist on purpose: `./missing-imag
18
18
19
19

20
20
21
-
When you run the build or look at the deploy log, you will see the warning for it. That warning is the plugin working as designed.
21
+
Hover the placeholder, or click or tap it, to see what is missing and where it was imported from. When you run the build or look at the deploy log, you will see the same file and line in the warning:
22
+
23
+
```txt
24
+
[vite-plugin-image-fallback] Could not find …/docs/plugins/missing-image-demo.png (imported by plugins/image-fallback.md:19). Using fallback image.
25
+
```
26
+
27
+
That warning is the plugin working as designed.
22
28
23
29
## Install
24
30
@@ -46,6 +52,7 @@ Only relative (`./foo.png`) and root-relative (`/foo.png`) imports are intercept
|`fallback`| gray "Missing Image Asset" SVG | A data URI, or any URL string Vite can serve. |
48
54
|`silent`|`false`| Suppress the console warning. |
55
+
|`hints`|`true`| Record what is missing, for the hints below. |
49
56
50
57
```ts
51
58
imageFallbackPlugin({
@@ -54,4 +61,25 @@ imageFallbackPlugin({
54
61
});
55
62
```
56
63
64
+
## Hints
65
+
66
+
Turn on the popovers in your theme. They work the same way as [Broken Links](/plugins/broken-links) and [HTML Escape's hints](/plugins/html-escape/#hints), and all three run side by side on this site.
Each placeholder gets a dashed outline and a popover that names the missing import, and the file and line that imported it. The plugin records them in a `#image-fallback=…` fragment on the placeholder's URL, which the browser ignores when it loads the image.
82
+
83
+
`enableImageFallbackHints(options)` takes `hover` (default `true`), `hoverDelay` (default `300` milliseconds) and `injectStyles` (default `true`), the same options as Broken Links. The colors follow the VitePress theme and can be changed with the `--image-fallback-hint-error` CSS variable.
84
+
57
85
[Source and full README on GitHub](https://github.com/binarynoir/vite-plugin-image-fallback)
0 commit comments