Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/preact #12

Merged
merged 3 commits into from
Jul 21, 2024
Merged
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
24 changes: 24 additions & 0 deletions apps/preact-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions apps/preact-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Preact</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions apps/preact-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "preact-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"preact": "^10.22.1"
},
"devDependencies": {
"@preact/preset-vite": "^2.8.3",
"typescript": "^5.2.2",
"vite": "^5.3.4",
"vite-plugin-hash-csp": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/preact-app/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions apps/preact-app/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.preact:hover {
filter: drop-shadow(0 0 2em #673ab8aa);
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

.button{
background-color: #673ab8;
color: white;
padding: 1em 2em;
border: none;
border-radius: 0.5em;
font-size: 1em;
cursor: pointer;
}
46 changes: 46 additions & 0 deletions apps/preact-app/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useState } from "preact/hooks";
import preactLogo from "./assets/preact.svg";
import viteLogo from "/vite.svg";
import "./app.css";

export function App() {
const [count, setCount] = useState(0);

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} class="logo" alt="Vite logo" />
</a>
<a href="https://preactjs.com" target="_blank">
<img src={preactLogo} class="logo preact" alt="Preact logo" />
</a>
</div>
<h1>Vite + Preact</h1>
<div class="card">
<button
className="button"
onClick={() => setCount((count) => count + 1)}
>
count is {count}
</button>
<p>
Edit <code>src/app.tsx</code> and save to test HMR
</p>
</div>
<p>
Check out{" "}
<a
href="https://preactjs.com/guide/v10/getting-started#create-a-vite-powered-preact-app"
target="_blank"
>
create-preact
</a>
, the official Preact + Vite starter
</p>
<p class="read-the-docs">
Click on the Vite and Preact logos to learn more
</p>
</>
);
}
1 change: 1 addition & 0 deletions apps/preact-app/src/assets/preact.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions apps/preact-app/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
5 changes: 5 additions & 0 deletions apps/preact-app/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { render } from 'preact'
import { App } from './app.tsx'
import './index.css'

render(<App />, document.getElementById('app')!)
1 change: 1 addition & 0 deletions apps/preact-app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
27 changes: 27 additions & 0 deletions apps/preact-app/tests/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test, expect } from "@playwright/test";

const TITLE = "Vite + Preact";

test("Index HTML Loaded", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveTitle(TITLE);
});

test("Loaded main JS script", async ({ page }) => {
await page.goto("/");
await expect(page.locator(`text=${TITLE}`)).toBeVisible();
});

test("Loaded CSS Styles", async ({ page }) => {
await page.goto("/");

const element = page.getByRole("heading", { name: TITLE });
const button = page.getByRole("button", { name: "count is" });
await expect(element).toBeVisible();

const color = await button.evaluate(
(el) => window.getComputedStyle(el).backgroundColor
);

expect(color).toBe("rgb(103, 58, 184)");
});
32 changes: 32 additions & 0 deletions apps/preact-app/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"paths": {
"react": ["./node_modules/preact/compat/"],
"react-dom": ["./node_modules/preact/compat/"]
},

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
11 changes: 11 additions & 0 deletions apps/preact-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
]
}
13 changes: 13 additions & 0 deletions apps/preact-app/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true,
"noEmit": true
},
"include": ["vite.config.ts"]
}
21 changes: 21 additions & 0 deletions apps/preact-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig, PluginOption } from "vite";
import preact from "@preact/preset-vite";
import csp from "vite-plugin-hash-csp";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
preact(),
csp({
dev: {
run: true,
},
}) as PluginOption, //This is a type assertion due to a monorepo issue regarding stylus, this is not needed in a normal project
],
preview: {
port: 4009,
},
server: {
port: 3009,
},
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"re:dev": "turbo dev --filter=remix-app",
"re:build": "turbo build --filter=remix-app",
"re:preview": "turbo preview --filter=remix-app",
"pr:dev": "turbo dev --filter=preact-app",
"pr:build": "turbo build --filter=preact-app",
"pr:preview": "turbo preview --filter=preact-app",
"vue:dev": "turbo dev --filter=vue-app",
"vue:build": "turbo build --filter=vue-app",
"vue:preview": "turbo preview --filter=vue-app",
Expand Down
12 changes: 12 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ const APPS = [
testDir: "./apps/vue/tests",
name: "Vue - Build",
},
{
url: "http://localhost:3009",
command: `pnpm pr:dev`,
testDir: "./apps/preact-app/tests",
name: "Preact - Dev",
},
{
url: "http://localhost:4009",
command: `pnpm pr:preview`,
testDir: "./apps/preact-app/tests",
name: "Preact - Build",
},
];

/**
Expand Down
Loading