Skip to content

Commit

Permalink
Set up RSD using Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
dgca committed Nov 7, 2024
1 parent aff0e4b commit 7e80561
Show file tree
Hide file tree
Showing 27 changed files with 9,052 additions and 11,885 deletions.
20,436 changes: 8,564 additions & 11,872 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/data-facade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@tanstack/react-query": "^5.28.14",
"react": "18.2.0",
"react": "18.3.1",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down
12 changes: 5 additions & 7 deletions packages/mobile-app/app/(tabs)/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Appearance, useColorScheme, View, Button } from "react-native";
import { useColorScheme, View, Text } from "react-native";
import { Button } from "@ironfish/tackle-box";

export default function UiKit() {
const scheme = useColorScheme();
return (
Expand All @@ -9,12 +11,8 @@ export default function UiKit() {
backgroundColor: scheme === "dark" ? "#333" : "#fff",
}}
>
<Button
title="Toggle color scheme"
onPress={() => {
Appearance.setColorScheme(scheme === "dark" ? "light" : "dark");
}}
/>
<Text>Hello world</Text>
<Button message="hello world" />
</View>
);
}
2 changes: 1 addition & 1 deletion packages/mobile-app/data/facades/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { chainHandlers } from "./chain/handlers";
import { chainDemoHandlers } from "./chain/demoHandlers";
import { contactsDemoHandlers } from "./contacts/demoHandlers";

const DEMO = false;
const DEMO = true;

export const facadeContext = createFacadeContext(
DEMO
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile-app/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module.exports = (() => {
},
assetExts: resolver.assetExts.filter((ext) => ext !== "svg"),
sourceExts: [...resolver.sourceExts, "svg"],
unstable_enablePackageExports: true,
unstable_conditionNames: ["browser", "require", "react-native"],
};

config.transformer = {
Expand Down
9 changes: 6 additions & 3 deletions packages/mobile-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.7",
"ironfish-native-module": "*",
"kysely": "^0.27.3",
"kysely": "^0.27.4",
"kysely-expo": "2.0.3",
"long": "^5.2.3",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"protobufjs": "^7.3.0",
"react": "18.2.0",
"react-native": "0.74.5",
"react": "18.3.1",
"react-native": "0.75.4",
"react-native-fs": "^2.20.0",
"react-native-safe-area-context": "4.10.8",
"react-native-screens": "3.32.0",
"react-native-svg": "15.2.0",
"react-strict-dom": "^0.0.28",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/mobile-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
"strict": true,
"moduleResolution": "node16"
}
}
24 changes: 24 additions & 0 deletions packages/tackle-box/.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?
50 changes: 50 additions & 0 deletions packages/tackle-box/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions packages/tackle-box/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions packages/tackle-box/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 + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions packages/tackle-box/lib/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { html, css } from "react-strict-dom";

const styles = css.create({
button: {
backgroundColor: {
default: "#000",
":hover": "lightblue",
":focus": "mediumpurple",
":active": "pink",
},
color: "white",
textAlign: "center",
paddingTop: 14,
paddingBottom: 14,
paddingLeft: 24,
paddingRight: 24,
fontSize: 20,
borderRadius: 9999,
},
});

type Props = {
message: string;
};

export function Button({ message }: Props) {
console.log({ message });
return (
<html.button style={styles.button}>{`Click me: ${message}`}</html.button>
);
}
1 change: 1 addition & 0 deletions packages/tackle-box/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Button } from "./components/Button/Button";
51 changes: 51 additions & 0 deletions packages/tackle-box/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@ironfish/tackle-box",
"private": true,
"version": "0.0.0",
"files": [
"dist"
],
"types": "./dist/tackle-box.d.ts",
"exports": {
".": {
"types": "./dist/tackle-box.d.ts",
"react-native": "./dist/main-native.umd.js",
"default": "./dist/main-web.umd.js"
}
},
"scripts": {
"dev": "vite",
"build": "npm run build:native && npm run build:web",
"build:web": "tsc -b && vite build --mode web",
"build:native": "tsc -b && vite build --mode native",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react-strict-dom": "^0.0.28"
},
"peerDependencies": {
"react": "^18",
"react-dom": "^18",
"react-native": "^0.74"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@stylexjs/babel-plugin": "^0.9.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"react": "18.3.1",
"react-native": "0.75.4",
"react-dom": "^18.3.1",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10",
"vite-plugin-babel": "^1.2.0",
"vite-plugin-dts": "^4.3.0"
}
}
1 change: 1 addition & 0 deletions packages/tackle-box/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.
42 changes: 42 additions & 0 deletions packages/tackle-box/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
35 changes: 35 additions & 0 deletions packages/tackle-box/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

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

return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<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 className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}

export default App
1 change: 1 addition & 0 deletions packages/tackle-box/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7e80561

Please sign in to comment.