Skip to content

Commit 0fa4fe8

Browse files
committed
feat(image-fallback): enable dev-server placeholder hints, bump to 0.4.0
1 parent b702941 commit 0fa4fe8

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎docs/plugins/image-fallback.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Run this site with `npm run docs:dev` and the demo image above looks like this:
5959
[vite-plugin-image-fallback] Could not find …/docs/plugins/missing-image-demo.png (requested by /plugins/image-fallback). Serving fallback image.
6060
```
6161

62-
The hint popovers below need the `#image-fallback=` fragment the build adds, so they appear in builds only. In dev, read the path on the placeholder instead.
62+
The hint popovers below work in dev too. Each placeholder response carries an `X-Image-Fallback` header with the missing path, and on a dev-server page the client script asks about each image with one `HEAD` request, then outlines and explains the placeholders it finds. In dev, the popover names the missing path but not the file and line, which only the build knows.
6363

6464
## Options
6565

@@ -96,6 +96,14 @@ export default {
9696

9797
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.
9898

99-
`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.
99+
`enableImageFallbackHints(options)` takes `hover` (default `true`), `hoverDelay` (default `300` milliseconds) and `injectStyles` (default `true`), the same options as Broken Links. It also takes `devPlaceholders`, on by default when the Vite dev server served the page, which turns the `HEAD` checks on or off. The colors follow the VitePress theme and can be changed with the `--image-fallback-hint-error` CSS variable.
100+
101+
To skip placeholders in your own code, for example in a click-to-zoom handler, use `isImageFallback(img)`. It is true for built placeholders, and for dev ones once they have been found:
102+
103+
```ts
104+
import { isImageFallback } from '@binarynoir/vite-plugin-image-fallback/client';
105+
106+
if (isImageFallback(img)) return; // nothing to zoom
107+
```
100108

101109
[Source and full README on GitHub](https://github.com/binarynoir/vite-plugin-image-fallback)

‎package-lock.json‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"format:check": "prettier --check ."
2323
},
2424
"devDependencies": {
25-
"@binarynoir/vite-plugin-image-fallback": "^0.3.0",
25+
"@binarynoir/vite-plugin-image-fallback": "^0.4.0",
2626
"@binarynoir/vite-plugin-optimize-images": "^0.1.9",
2727
"@binarynoir/vitepress-auto-navbar": "^0.4.1",
2828
"@binarynoir/vitepress-auto-sidebar": "^0.6.1",

0 commit comments

Comments
 (0)