Skip to content

Commit

Permalink
feat: solid
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Oct 15, 2023
1 parent 031e8fa commit 332c2e1
Show file tree
Hide file tree
Showing 21 changed files with 2,983 additions and 256 deletions.
28 changes: 28 additions & 0 deletions apps/examples/solid-start/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

dist
.solid
.output
.vercel
.netlify
netlify

# Environment
.env
.env*.local

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
*.launch
.settings/

# Temp
gitignore

# System Files
.DS_Store
Thumbs.db
30 changes: 30 additions & 0 deletions apps/examples/solid-start/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SolidStart

Everything you need to build a Solid project, powered by [`solid-start`](https://start.solidjs.com);

## 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 _adapters_, 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 adapter, add it to the `devDependencies` in `package.json` and specify in your `vite.config.js`.
29 changes: 29 additions & 0 deletions apps/examples/solid-start/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@urami/demo-solid",
"type": "module",
"private": true,
"scripts": {
"dev": "solid-start dev --port ${PORT:-5175}",
"build": "solid-start build",
"start": "solid-start start"
},
"dependencies": {
"@solidjs/meta": "^0.28.6",
"@solidjs/router": "^0.8.3",
"@urami/core": "workspace:*",
"@urami/solid": "workspace:*",
"sharp": "^0.32.5",
"solid-js": "^1.7.12",
"solid-start": "^0.3.6"
},
"devDependencies": {
"@types/node": "^18.17.5",
"esbuild": "^0.14.54",
"postcss": "^8.4.28",
"solid-start-node": "^0.3.6",
"vite": "^4.4.9"
},
"engines": {
"node": ">=18"
}
}
Binary file added apps/examples/solid-start/public/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions apps/examples/solid-start/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { mount, StartClient } from "solid-start/entry-client";

mount(() => <StartClient />, document);
9 changes: 9 additions & 0 deletions apps/examples/solid-start/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
createHandler,
renderAsync,
StartServer,
} from "solid-start/entry-server";

export default createHandler(
renderAsync((event) => <StartServer event={event} />)
);
1 change: 1 addition & 0 deletions apps/examples/solid-start/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="solid-start/env" />
37 changes: 37 additions & 0 deletions apps/examples/solid-start/src/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @refresh reload
import { Suspense } from 'solid-js'
import {
A,
Body,
ErrorBoundary,
FileRoutes,
Head,
Html,
Meta,
Routes,
Scripts,
Title,
} from 'solid-start'

export default function Root() {
return (
<Html lang="en">
<Head>
<Title>SolidStart - Bare</Title>
<Meta charset="utf-8" />
<Meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com"></script>
</Head>
<Body>
<Suspense>
<ErrorBoundary>
<Routes>
<FileRoutes />
</Routes>
</ErrorBoundary>
</Suspense>
<Scripts />
</Body>
</Html>
)
}
19 changes: 19 additions & 0 deletions apps/examples/solid-start/src/routes/[...404].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Title } from "solid-start";
import { HttpStatusCode } from "solid-start/server";

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>
);
}
9 changes: 9 additions & 0 deletions apps/examples/solid-start/src/routes/api/_image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createRequestHandler } from '@urami/core'

import type { APIEvent } from 'solid-start/api'

const handler = createRequestHandler({
remoteDomains: ['demo.rayriffy.com'],
})

export const GET = ({ request }: APIEvent) => handler(request)
33 changes: 33 additions & 0 deletions apps/examples/solid-start/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Image from '@urami/solid'

export default function Home() {
return (
<main class="max-w-xl mx-auto m-4 py-4">
<section class="">
<h1 class="text-gray-900 font-bold text-3xl">Urami</h1>
<p class="text-gray-700">
Automatic image optimization for all! This is a demo for{' '}
<b>Solid Start</b>
</p>
</section>

<section class="py-8">
<a
href="https://urami.dev"
class="inline-flex items-center rounded-md border border-transparent bg-indigo-100 px-4 py-2 text-sm font-medium text-indigo-700 hover:bg-indigo-200 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
>
Documentation
</a>
</section>

<h2 class="text-2xl font-bold pb-4">Demo</h2>
<Image
src="https://demo.rayriffy.com/tom-scott.jpg"
width={801}
height={801}
alt="Tom Scott"
class="rounded-xl shadow-md"
/>
</main>
)
}
16 changes: 16 additions & 0 deletions apps/examples/solid-start/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"jsxImportSource": "solid-js",
"jsx": "preserve",
"strict": true,
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"]
}
}
}
6 changes: 6 additions & 0 deletions apps/examples/solid-start/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import solid from "solid-start/vite";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [solid()],
});
21 changes: 11 additions & 10 deletions apps/examples/sveltekit/src/app.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
8 changes: 5 additions & 3 deletions apps/examples/sveltekit/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

<main class="max-w-xl mx-auto m-4 py-4">
<section class="">
<h1 class="text-gray-900 font-bold text-3xl">svelte-aio</h1>
<p class="text-gray-700">Automatic image optimization for SvelteKit.</p>
<h1 class="text-gray-900 font-bold text-3xl">Urami</h1>
<p class="text-gray-700">
Automatic image optimization for all! This is a demo for <b>SvelteKit</b>
</p>
</section>

<section class="py-8">
<a
href="https://github.com/rayriffy/svelte-aio#readme"
href="https://urami.dev"
class="inline-flex items-center rounded-md border border-transparent bg-indigo-100 px-4 py-2 text-sm font-medium text-indigo-700 hover:bg-indigo-200 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
>
Documentation
Expand Down
1 change: 0 additions & 1 deletion apps/examples/sveltekit/src/routes/api/_image/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { RequestHandler } from '@sveltejs/kit'

const handler = createRequestHandler({
remoteDomains: ['demo.rayriffy.com'],
allowedDomains: ['svelte-aio.vercel.app'],
})

export const GET: RequestHandler = event => handler(event.request)
52 changes: 52 additions & 0 deletions packages/solid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@urami/solid",
"version": "0.0.0",
"description": "Utilities function for automatic image optimization",
"author": {
"name": "Phumrapee Limpiancop",
"email": "[email protected]",
"url": "https://rayriffy.com"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rayriffy/urami.git"
},
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"src",
"dist"
],
"scripts": {
"build": "tsup --format esm --dts --sourcemap",
"dev": "pnpm run build --watch"
},
"keywords": [],
"peerDependencies": {
"solid-js": "^1.7.12"
},
"dependencies": {
"@urami/utils": "workspace:*"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.3",
"@urami/types": "workspace:*",
"solid-js": "^1.7.12",
"tsup-preset-solid": "^2.1.0"
},
"browser": {},
"exports": {
"solid": "./dist/index.jsx",
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"typesVersions": {}
}
33 changes: 33 additions & 0 deletions packages/solid/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defaultLoader, buildSource } from '@urami/utils'

import type { Component, JSX } from 'solid-js'
import type { Loader } from '@urami/types'

export interface ImageProps extends JSX.ImgHTMLAttributes<HTMLImageElement> {
src: string
width: number
quality?: number
loader?: Loader
}

const Image: Component<ImageProps> = ({
src,
width,
quality = 75,
loader = defaultLoader,
...rest
}) => {
const builtProps = buildSource(loader, src, width, quality)

return (
<img
src={builtProps.src}
srcset={builtProps.srcSet}
decoding="async"
loading="lazy"
{...rest}
/>
)
}

export default Image
13 changes: 13 additions & 0 deletions packages/solid/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"module": "es2022",
"lib": ["es2023", "DOM"],
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"noEmit": true,
"jsx": "preserve",
"jsxImportSource": "solid-js"
}
}
Loading

0 comments on commit 332c2e1

Please sign in to comment.