这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(examples): add example-with-vite-react #9620

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

Merged
merged 2 commits into from
Jan 24, 2025
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
5 changes: 5 additions & 0 deletions examples/with-vite-react/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@repo/eslint-config/index.js"],
};
11 changes: 11 additions & 0 deletions examples/with-vite-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
node_modules
.turbo
*.log
dist
dist-ssr
*.local
.env
.cache
server/dist
public/dist
1 change: 1 addition & 0 deletions examples/with-vite-react/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers = true
32 changes: 32 additions & 0 deletions examples/with-vite-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# `Turborepo` Vite starter

This is an official starter Turborepo.

## Using this example

Run the following command:

```sh
npx create-turbo@latest -e with-vite-react
```

## What's inside?

This Turborepo includes the following packages and apps:

### Apps and Packages

- `web`: react [vite](https://vitejs.dev) ts app
- `@repo/ui`: a stub component library shared by `web` application
- `@repo/eslint-config`: shared `eslint` configurations
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo

Each package and app is 100% [TypeScript](https://www.typescriptlang.org/).

### Utilities

This Turborepo has some additional tools already setup for you:

- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting
5 changes: 5 additions & 0 deletions examples/with-vite-react/apps/web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@repo/eslint-config/index.js"],
};
13 changes: 13 additions & 0 deletions examples/with-vite-react/apps/web/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 + React</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions examples/with-vite-react/apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --clearScreen false",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint \"src/**/*.ts\""
},
"dependencies": {
"@repo/ui": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^3.1.0",
"eslint": "^8.57.0",
"typescript": "5.5.4",
"vite": "^5.1.4"
}
}
1 change: 1 addition & 0 deletions examples/with-vite-react/apps/web/public/typescript.svg
Loading
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 examples/with-vite-react/apps/web/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.
26 changes: 26 additions & 0 deletions examples/with-vite-react/apps/web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import { createRoot } from "react-dom/client";
import "./style.css";
import typescriptLogo from "/typescript.svg";
import { Header, Counter } from "@repo/ui";

const App = () => (
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" className="logo" alt="Vite logo" />
</a>
<a href="https://www.typescriptlang.org/" target="_blank">
<img
src={typescriptLogo}
className="logo vanilla"
alt="TypeScript logo"
/>
</a>
<Header title="Web" />
<div className="card">
<Counter />
</div>
</div>
);

createRoot(document.getElementById("app")!).render(<App />);
97 changes: 97 additions & 0 deletions examples/with-vite-react/apps/web/src/style.css
Original file line number Diff line number Diff line change
@@ -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 examples/with-vite-react/apps/web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
7 changes: 7 additions & 0 deletions examples/with-vite-react/apps/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@repo/typescript-config/vite.json",
"include": ["src"],
"compilerOptions": {
"jsx": "react-jsx"
}
}
6 changes: 6 additions & 0 deletions examples/with-vite-react/apps/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
plugins: [react()],
});
16 changes: 16 additions & 0 deletions examples/with-vite-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"turbo": "^2.3.3"
},
"packageManager": "pnpm@8.15.6",
"name": "with-vite-react"
}
19 changes: 19 additions & 0 deletions examples/with-vite-react/packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
env: {
node: true,
},
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
plugins: ["@typescript-eslint"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
},
rules: {
"@typescript-eslint/no-non-null-assertion": "off",
},
};
14 changes: 14 additions & 0 deletions examples/with-vite-react/packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@repo/eslint-config",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"eslint-config-prettier": "^9.1.0"
},
"publishConfig": {
"access": "public"
}
}
20 changes: 20 additions & 0 deletions examples/with-vite-react/packages/typescript-config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@repo/typescript-config",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"jsx": "react-jsx"
}
}
16 changes: 16 additions & 0 deletions examples/with-vite-react/packages/typescript-config/vite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./base.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"sourceMap": true,
"resolveJsonModule": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true
},
"exclude": ["node_modules"]
}
10 changes: 10 additions & 0 deletions examples/with-vite-react/packages/ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
ignorePatterns: [".eslintrc.cjs"],
extends: ["@repo/eslint-config/index.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
11 changes: 11 additions & 0 deletions examples/with-vite-react/packages/ui/components/counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { useState } from "react";

export const Counter: React.FC = () => {
const [count, setCount] = useState(0);

return (
<button id="counter" type="button" onClick={() => setCount(count + 1)}>
{count}
</button>
);
};
13 changes: 13 additions & 0 deletions examples/with-vite-react/packages/ui/components/header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

interface HeaderProps {
title: string;
}

export const Header: React.FC<HeaderProps> = ({ title }) => {
return (
<header id="header">
<h1>{title}</h1>
</header>
);
};
2 changes: 2 additions & 0 deletions examples/with-vite-react/packages/ui/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./header";
export * from "./counter";
Loading
Loading