Skip to content

Commit 1864b20

Browse files
committed
fix(image): setup example
1 parent 82ada9a commit 1864b20

File tree

6 files changed

+130
-2
lines changed

6 files changed

+130
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ tsconfig.tsbuildinfo
5555

5656
apps/tests/**/test-results
5757
.solid-start
58+
59+
.image

apps/tests/src/images/example.jpg

237 KB
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { StartImage as Image } from "@solidjs/start/image";
2+
import { type JSX, onMount, Show } from "solid-js";
3+
import exampleImage from "../images/example.jpg?image";
4+
5+
interface PlaceholderProps {
6+
show: () => void;
7+
}
8+
9+
function Placeholder(props: PlaceholderProps): JSX.Element {
10+
onMount(() => {
11+
props.show();
12+
});
13+
14+
return <div>Loading...</div>;
15+
}
16+
17+
export default function App(): JSX.Element {
18+
return (
19+
<div style={{ width: "50vw" }}>
20+
<Image
21+
{...exampleImage}
22+
alt="example"
23+
fallback={(visible, show) => (
24+
<Show when={visible()}>
25+
<Placeholder show={show} />
26+
</Show>
27+
)}
28+
/>
29+
</div>
30+
);
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { StartImage as Image } from "@solidjs/start/image";
2+
import { type JSX, onMount, Show } from "solid-js";
3+
// local
4+
// import exampleImage from './example.jpg?image';
5+
6+
// remote
7+
import exampleImage from "image:foobar";
8+
9+
interface PlaceholderProps {
10+
show: () => void;
11+
}
12+
13+
function Placeholder(props: PlaceholderProps): JSX.Element {
14+
onMount(() => {
15+
props.show();
16+
});
17+
18+
return <div>Loading...</div>;
19+
}
20+
21+
export default function App(): JSX.Element {
22+
return (
23+
<div style={{ width: "50vw" }}>
24+
<Image
25+
{...exampleImage}
26+
alt="example"
27+
fallback={(visible, show) => (
28+
<Show when={visible()}>
29+
<Placeholder show={show} />
30+
</Show>
31+
)}
32+
/>
33+
</div>
34+
);
35+
}

apps/tests/vite.config.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
import { defineConfig } from "vite";
2-
import { solidStart } from "../../packages/start/src/config";
32
import { nitroV2Plugin } from "../../packages/start-nitro-v2-vite-plugin/src";
3+
import { solidStart } from "../../packages/start/src/config";
44

55
export default defineConfig({
66
server: {
77
port: 3000,
88
},
9-
plugins: [solidStart(), nitroV2Plugin()],
9+
plugins: [
10+
solidStart({
11+
image: {
12+
local: {
13+
sizes: [480, 600],
14+
quality: 80,
15+
publicPath: "public",
16+
},
17+
remote: {
18+
transformURL(url) {
19+
return {
20+
src: {
21+
source: `https://picsum.photos/seed/${url}/1200/900.webp`,
22+
width: 1080,
23+
height: 760,
24+
},
25+
variants: [
26+
{
27+
path: `https://picsum.photos/seed/${url}/800/600.jpg`,
28+
width: 800,
29+
type: "image/jpeg",
30+
},
31+
{
32+
path: `https://picsum.photos/seed/${url}/400/300.jpg`,
33+
width: 400,
34+
type: "image/jpeg",
35+
},
36+
{
37+
path: `https://picsum.photos/seed/${url}/800/600.png`,
38+
width: 800,
39+
type: "image/png",
40+
},
41+
{
42+
path: `https://picsum.photos/seed/${url}/400/300.png`,
43+
width: 400,
44+
type: "image/png",
45+
},
46+
],
47+
};
48+
},
49+
},
50+
},
51+
}),
52+
nitroV2Plugin(),
53+
],
1054
});

packages/start/env.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,19 @@ declare namespace App {
77
[key: string | symbol]: any;
88
}
99
}
10+
11+
declare module 'image:*' {
12+
import type { StartImageProps } from "./src/image.ts";
13+
14+
const props: Pick<StartImageProps<unknown>, 'src' | 'transformer'>;
15+
16+
export default props;
17+
}
18+
19+
declare module '*?image' {
20+
import type { StartImageProps } from "./src/image.ts";
21+
22+
const props: Pick<StartImageProps<unknown>, 'src' | 'transformer'>;
23+
24+
export default props;
25+
}

0 commit comments

Comments
 (0)