Skip to content

Commit

Permalink
Merge pull request #5 from kazupon/example
Browse files Browse the repository at this point in the history
add example code
  • Loading branch information
kazupon committed Aug 4, 2022
2 parents b5e8678 + 5de7220 commit b885520
Show file tree
Hide file tree
Showing 23 changed files with 461 additions and 57 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,4 +1,5 @@
dist
coverage
playground
__tests__
__test__
10 changes: 10 additions & 0 deletions package.json
Expand Up @@ -42,6 +42,8 @@
"scripts": {
"build": "unbuild",
"test": "vitest run test",
"play:dev": "pnpm --filter vite-app-prj dev",
"play:test": "pnpm --filter vite-app-prj test",
"fix": "run-p lint:fix format:fix",
"format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{js,json,html}'",
"format:fix": "pnpm format --write",
Expand All @@ -55,6 +57,7 @@
"express": "^4.18.1",
"get-port-please": "^2.5.0",
"ohmyfetch": "^0.4.18",
"picocolors": "^1.0.0",
"vite": "^3.0.4"
},
"peerDependencies": {
Expand All @@ -81,6 +84,13 @@
"unbuild": "^0.7.6",
"vitest": "^0.20.3"
},
"pnpm": {
"overrides": {
"vite": "^3.0.4",
"vitest": "^0.20.3",
"vite-test-utils": "workspace:*"
}
},
"gitHooks": {
"pre-commit": "lint-staged"
},
Expand Down
24 changes: 24 additions & 0 deletions playground/vite-app-prj/.gitignore
@@ -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?
14 changes: 14 additions & 0 deletions playground/vite-app-prj/e2e/app.spec.ts
@@ -0,0 +1,14 @@
import { setup, createPage } from 'vite-test-utils'

await setup()

test('counting', async () => {
const page = await createPage('/')

const button = await page.locator('#counter')
await button.click()
await button.click()
await button.click()

expect(await button.innerText()).toBe('count is 3')
})
15 changes: 15 additions & 0 deletions playground/vite-app-prj/favicon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions playground/vite-app-prj/index.html
@@ -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 + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions playground/vite-app-prj/package.json
@@ -0,0 +1,19 @@
{
"name": "vite-app-prj",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "vitest run spec"
},
"devDependencies": {
"typescript": "^4.6.4",
"vite": "^3.0.0",
"playwright": "^1.24.0",
"vite-test-utils": "workspace:*",
"vitest": "^0.19.0"
}
}
1 change: 1 addition & 0 deletions playground/vite-app-prj/public/vite.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions playground/vite-app-prj/src/counter.ts
@@ -0,0 +1,9 @@
export function setupCounter(element: HTMLButtonElement) {
let counter = 0
const setCounter = (count: number) => {
counter = count
element.innerHTML = `count is ${counter}`
}
element.addEventListener('click', () => setCounter(++counter))
setCounter(0)
}
23 changes: 23 additions & 0 deletions playground/vite-app-prj/src/main.ts
@@ -0,0 +1,23 @@
import './style.css'
import typescriptLogo from './typescript.svg'
import { setupCounter } from './counter'

document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://www.typescriptlang.org/" target="_blank">
<img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
</a>
<h1>Vite + TypeScript</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite and TypeScript logos to learn more
</p>
</div>
`

setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
97 changes: 97 additions & 0 deletions playground/vite-app-prj/src/style.css
@@ -0,0 +1,97 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
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;
-webkit-text-size-adjust: 100%;
}

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;
}

#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #f7df1eaa);
}

.card {
padding: 2em;
}

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

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;
}
}
1 change: 1 addition & 0 deletions playground/vite-app-prj/src/typescript.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions playground/vite-app-prj/src/vite-env.d.ts
@@ -0,0 +1 @@
/// <reference types="vite/client" />
21 changes: 21 additions & 0 deletions playground/vite-app-prj/tsconfig.json
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"types": ["vitest/globals", "vitest/importMeta"]
},
"include": ["src"]
}
10 changes: 10 additions & 0 deletions playground/vite-app-prj/vitest.config.ts
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
globals: true,
deps: {
inline: [/vite-test-utils/]
}
}
})

0 comments on commit b885520

Please sign in to comment.