Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/fixtures/image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SolidStart Image Fixture

Fixture app for exercising the `@solidjs/image` component and Vite plugin.

## Creating a project

```bash
# create a new project in the current directory
npm init solid@latest

# create a new project in my-app
npm init solid@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

Solid apps are built with _presets_, which optimise your project for deployment to different environments.

By default, `npm run build` will generate a Node app that you can run with `npm start`. To use a different preset, add it to the `devDependencies` in `package.json` and specify in your `app.config.js`.
20 changes: 20 additions & 0 deletions apps/fixtures/image/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "fixture-image",
"type": "module",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build"
},
"dependencies": {
"@solidjs/image": "workspace:*",
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.15.0",
"@solidjs/start": "workspace:*",
"solid-js": "^1.9.9",
"vite": "7.1.10"
},
"engines": {
"node": ">=22"
}
}
Binary file added apps/fixtures/image/public/favicon.ico
Binary file not shown.
39 changes: 39 additions & 0 deletions apps/fixtures/image/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
body {
font-family: Gordita, Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

a {
margin-right: 1rem;
}

main {
text-align: center;
padding: 1em;
margin: 0 auto;
}

h1 {
color: #335d92;
text-transform: uppercase;
font-size: 4rem;
font-weight: 100;
line-height: 1.1;
margin: 4rem auto;
max-width: 14rem;
}

p {
max-width: 14rem;
margin: 2rem auto;
line-height: 1.35;
}

@media (min-width: 480px) {
h1 {
max-width: none;
}

p {
max-width: none;
}
}
22 changes: 22 additions & 0 deletions apps/fixtures/image/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MetaProvider, Title } from "@solidjs/meta";
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
import "./app.css";

export default function App() {
return (
<Router
root={props => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<a href="/">Index</a>
<a href="/about">About</a>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}
4 changes: 4 additions & 0 deletions apps/fixtures/image/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @refresh reload
import { mount, StartClient } from "@solidjs/start/client";

mount(() => <StartClient />, document.getElementById("app")!);
21 changes: 21 additions & 0 deletions apps/fixtures/image/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @refresh reload
import { createHandler, StartServer } from "@solidjs/start/server";

export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
{assets}
</head>
<body>
<div id="app">{children}</div>
{scripts}
</body>
</html>
)}
/>
));
Binary file added apps/fixtures/image/src/images/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions apps/fixtures/image/src/routes/[...404].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Title } from "@solidjs/meta";
import { HttpStatusCode } from "@solidjs/start";

export default function NotFound() {
return (
<main>
<Title>Not Found</Title>
<HttpStatusCode code={404} />
<h1>Page Not Found</h1>
<p>
Visit{" "}
<a href="https://start.solidjs.com" target="_blank">
start.solidjs.com
</a>{" "}
to learn how to build SolidStart apps.
</p>
</main>
);
}
24 changes: 24 additions & 0 deletions apps/fixtures/image/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Image } from "@solidjs/image";
import { Title } from "@solidjs/meta";
import imageData from "../images/example.jpg?image";

const { src, transformer } = imageData;

export default function Home() {
return (
<main>
<Title>Image Fixture</Title>
<h1>Image fixture</h1>
<p>
This fixture exercises the local image pipeline and the Start image component.
</p>
<div style={{ width: "60vw", "margin-left": "auto", "margin-right": "auto", background: "white", padding: "1rem" }}>
<Image
src={src}
transformer={transformer}
alt="Example"
/>
</div>
</main>
);
}
55 changes: 55 additions & 0 deletions apps/fixtures/image/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// <reference types="vite/client" />

type StartImageMIME =
| "image/avif"
| "image/jpeg"
| "image/png"
| "image/webp"
| "image/tiff";

interface StartImageVariant {
path: string;
width: number;
type: StartImageMIME;
}

interface StartImageSource<T> {
source: string;
width: number;
height: number;
options: T;
}

interface StartImageTransformer<T> {
transform: (source: StartImageSource<T>) => StartImageVariant | StartImageVariant[];
}

declare module "*.jpg?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}

declare module "*.png?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}

declare module "*.jpeg?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}

declare module "*.webp?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}

declare module "*.gif?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}

declare module "*.svg?image" {
const props: { src: StartImageSource<unknown>; transformer?: StartImageTransformer<unknown> };
export default props;
}
19 changes: 19 additions & 0 deletions apps/fixtures/image/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"allowJs": true,
"strict": true,
"noEmit": true,
"isolatedModules": true,
"paths": {
"~/*": ["./src/*"],
},
},
"include": ["src/**/*", "../../packages/image/env.d.ts", "../../packages/start/env.d.ts"]
}
52 changes: 52 additions & 0 deletions apps/fixtures/image/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { defineConfig } from "vite";
import { imagePlugin } from "../../../packages/image/src/vite";
import { solidStart } from "../../../packages/start/src/config";
import { nitroV2Plugin } from "../../../packages/start-nitro-v2-vite-plugin/src";

export default defineConfig({
plugins: [
imagePlugin({
local: {
sizes: [480, 600],
quality: 80,
output: ["avif"],
publicPath: "public",
},
remote: {
transformURL(url) {
return {
src: {
source: `https://picsum.photos/seed/${url}/1200/900.webp`,
width: 1080,
height: 760,
},
variants: [
{
path: `https://picsum.photos/seed/${url}/800/600.jpg`,
width: 800,
type: "image/jpeg",
},
{
path: `https://picsum.photos/seed/${url}/400/300.jpg`,
width: 400,
type: "image/jpeg",
},
{
path: `https://picsum.photos/seed/${url}/800/600.png`,
width: 800,
type: "image/png",
},
{
path: `https://picsum.photos/seed/${url}/400/300.png`,
width: 400,
type: "image/png",
},
],
};
},
},
}),
solidStart(),
nitroV2Plugin(),
],
});
1 change: 1 addition & 0 deletions apps/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.15.3",
"@solidjs/image": "workspace:*",
"@solidjs/start": "workspace:*",
"@solidjs/testing-library": "^0.8.10",
"@testing-library/jest-dom": "^6.6.2",
Expand Down
4 changes: 2 additions & 2 deletions apps/tests/src/routes/image-local.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StartImage as Image } from "@solidjs/start/image";
import { Image } from "@solidjs/image";
import { type JSX, onMount, Show } from "solid-js";
import exampleImage from "../images/example.jpg?image";

Expand All @@ -20,7 +20,7 @@ export default function App(): JSX.Element {
<Image
{...exampleImage}
alt="example"
fallback={(visible, show) => (
fallback={(visible: () => boolean, show: () => void) => (
<Show when={visible()}>
<Placeholder show={show} />
</Show>
Expand Down
4 changes: 2 additions & 2 deletions apps/tests/src/routes/image-remote.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StartImage as Image } from "@solidjs/start/image";
import { Image } from "@solidjs/image";
import { type JSX, onMount, Show } from "solid-js";
// local
// import exampleImage from './example.jpg?image';
Expand All @@ -24,7 +24,7 @@ export default function App(): JSX.Element {
<Image
{...exampleImage}
alt="example"
fallback={(visible, show) => (
fallback={(visible: () => boolean, show: () => void) => (
<Show when={visible()}>
<Placeholder show={show} />
</Show>
Expand Down
Loading
Loading