Skip to content

Commit 8d1eda5

Browse files
Merge pull request #29 from simpleanalytics/feat/react-package
feat(react): add react package and example
2 parents d1a3fc8 + a631bed commit 8d1eda5

28 files changed

+3031
-1684
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Package
1+
name: Release Package (Next.js)
22

33
on:
44
push:
@@ -9,7 +9,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
99

1010
jobs:
1111
release:
12-
name: Release
12+
name: Release Package (Next.js)
1313
runs-on: ubuntu-latest
1414
env:
1515
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}

.github/workflows/publish-preview.yaml renamed to .github/workflows/publish-preview-next.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
name: Publish Preview Package
1+
name: Publish Preview Package (Next.js)
22
on: [push, pull_request]
33

44
jobs:
55
build:
6+
name: Publish Preview Package (Next.js)
67
runs-on: ubuntu-latest
78
env:
89
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
@@ -35,5 +36,5 @@ jobs:
3536
- name: Build package
3637
run: pnpm build --filter=@simpleanalytics/next
3738

38-
- name: Publish package
39-
run: pnpx pkg-pr-new publish './packages/analytics'
39+
- name: Publish Next preview package
40+
run: pnpx pkg-pr-new publish './packages/analytics'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish Preview Package (React.js)
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
name: Publish Preview Package (React.js)
7+
runs-on: ubuntu-latest
8+
env:
9+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
10+
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Enable Corepack
17+
run: npm i -g corepack@latest && corepack enable
18+
19+
- name: Setup Node.js v22 LTS
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
cache: "pnpm"
24+
25+
- name: Cache Turborepo build setup
26+
uses: actions/cache@v4
27+
with:
28+
path: .turbo
29+
key: ${{ runner.os }}-turbo-${{ github.sha }}
30+
restore-keys: |
31+
${{ runner.os }}-turbo-
32+
33+
- name: Install dependencies
34+
run: pnpm install
35+
36+
- name: Build package
37+
run: pnpm build --filter=@simpleanalytics/react
38+
39+
- name: Publish React preview package
40+
run: pnpx pkg-pr-new publish './packages/react'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release Package (React.js)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release Package (React.js)
13+
runs-on: ubuntu-latest
14+
env:
15+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
16+
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Enable Corepack
23+
run: npm i -g corepack@latest && corepack enable
24+
25+
- name: Setup Node.js v22 LTS
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 22
29+
cache: "pnpm"
30+
registry-url: https://registry.npmjs.org
31+
32+
- name: Cache Turborepo build setup
33+
uses: actions/cache@v4
34+
with:
35+
path: .turbo
36+
key: ${{ runner.os }}-turbo-${{ github.sha }}
37+
restore-keys: |
38+
${{ runner.os }}-turbo-
39+
40+
- name: Install dependencies
41+
run: pnpm install
42+
43+
- name: Build package
44+
run: pnpm build --filter=@simpleanalytics/react
45+
46+
- name: Publish package
47+
shell: bash
48+
run: pnpm publish --filter=@simpleanalytics/react --access public --no-git-checks
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

examples/reactjs/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## React Compiler
11+
12+
The React Compiler is currently not compatible with SWC. See [this issue](https://github.com/vitejs/vite-plugin-react/issues/428) for tracking the progress.
13+
14+
## Expanding the ESLint configuration
15+
16+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17+
18+
```js
19+
export default defineConfig([
20+
globalIgnores(["dist"]),
21+
{
22+
files: ["**/*.{ts,tsx}"],
23+
extends: [
24+
// Other configs...
25+
26+
// Remove tseslint.configs.recommended and replace with this
27+
tseslint.configs.recommendedTypeChecked,
28+
// Alternatively, use this for stricter rules
29+
tseslint.configs.strictTypeChecked,
30+
// Optionally, add this for stylistic rules
31+
tseslint.configs.stylisticTypeChecked,
32+
33+
// Other configs...
34+
],
35+
languageOptions: {
36+
parserOptions: {
37+
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
38+
tsconfigRootDir: import.meta.dirname,
39+
},
40+
// other options...
41+
},
42+
},
43+
]);
44+
```
45+
46+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47+
48+
```js
49+
// eslint.config.js
50+
import reactX from "eslint-plugin-react-x";
51+
import reactDom from "eslint-plugin-react-dom";
52+
53+
export default defineConfig([
54+
globalIgnores(["dist"]),
55+
{
56+
files: ["**/*.{ts,tsx}"],
57+
extends: [
58+
// Other configs...
59+
// Enable lint rules for React
60+
reactX.configs["recommended-typescript"],
61+
// Enable lint rules for React DOM
62+
reactDom.configs.recommended,
63+
],
64+
languageOptions: {
65+
parserOptions: {
66+
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
67+
tsconfigRootDir: import.meta.dirname,
68+
},
69+
// other options...
70+
},
71+
},
72+
]);
73+
```

examples/reactjs/eslint.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
7+
8+
export default defineConfig([
9+
globalIgnores(['dist']),
10+
{
11+
files: ['**/*.{ts,tsx}'],
12+
extends: [
13+
js.configs.recommended,
14+
tseslint.configs.recommended,
15+
reactHooks.configs['recommended-latest'],
16+
reactRefresh.configs.vite,
17+
],
18+
languageOptions: {
19+
ecmaVersion: 2020,
20+
globals: globals.browser,
21+
},
22+
},
23+
])

examples/reactjs/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>reactjs</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

examples/reactjs/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "reactjs",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"lint": "eslint .",
10+
"preview": "vite preview"
11+
},
12+
"dependencies": {
13+
"@simpleanalytics/react": "workspace:*",
14+
"react": "^19.1.1",
15+
"react-dom": "^19.1.1"
16+
},
17+
"devDependencies": {
18+
"@eslint/js": "^9.36.0",
19+
"@types/node": "^24.6.0",
20+
"@types/react": "^19.1.16",
21+
"@types/react-dom": "^19.1.9",
22+
"@vitejs/plugin-react-swc": "^4.1.0",
23+
"eslint": "^9.36.0",
24+
"eslint-plugin-react-hooks": "^5.2.0",
25+
"eslint-plugin-react-refresh": "^0.4.22",
26+
"globals": "^16.4.0",
27+
"typescript": "~5.9.3",
28+
"typescript-eslint": "^8.45.0",
29+
"vite": "^7.1.7"
30+
}
31+
}

examples/reactjs/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/reactjs/src/App.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}

0 commit comments

Comments
 (0)