Skip to content

Commit

Permalink
feat(vite-react): add empty vite-react app
Browse files Browse the repository at this point in the history
  • Loading branch information
secundant committed Dec 8, 2023
1 parent c87137a commit 7111860
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/vite-react/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { presets, configure } = require('eslint-kit');

module.exports = configure({
root: __dirname,
presets: [
presets.react(),
presets.imports(),
presets.prettier(),
presets.effector(),
presets.typescript(),
],
extend: {
ignorePatterns: ['node_modules', 'dist'],
rules: {
'import/extensions': 'off',
},
},
});
24 changes: 24 additions & 0 deletions apps/vite-react/.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?
30 changes: 30 additions & 0 deletions apps/vite-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions apps/vite-react/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>Example Vite React Application</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/app/index.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions apps/vite-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "vite-react",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}
5 changes: 5 additions & 0 deletions apps/vite-react/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { createPostcssConfig } = require('@my-org/config/postcss');

module.exports = createPostcssConfig(__dirname, {
tailwindFile: 'tailwind.config.cjs',
});
14 changes: 14 additions & 0 deletions apps/vite-react/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"name": "vite-react",
"sourceRoot": "apps/vite-react/src",
"projectType": "application",
"tags": [],
"targets": {
"lint": {},
"storybook": {},
"typecheck": {},
"test-storybook": {},
"build-storybook": {}
}
}
1 change: 1 addition & 0 deletions apps/vite-react/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.
9 changes: 9 additions & 0 deletions apps/vite-react/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import '../shared/styles.css';
import { createRoot } from 'react-dom/client';
import { appInitialized } from './model.ts';
import { RoutesView } from './router.ts';

const root = createRoot(document.querySelector('#root')!);

root.render(<RoutesView />);
appInitialized();
12 changes: 12 additions & 0 deletions apps/vite-react/src/app/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createEvent, createStore, sample } from 'effector';
import { createBrowserHistory } from 'history';
import { router } from './router.ts';

export const appInitialized = createEvent();
export const $history = createStore(createBrowserHistory());

sample({
clock: appInitialized,
source: $history,
target: router.setHistory,
});
21 changes: 21 additions & 0 deletions apps/vite-react/src/app/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createHistoryRouter } from 'atomic-router';
import { createRoutesView } from 'atomic-router-react';
import { HomePage } from '../pages/home';

export const router = createHistoryRouter({
routes: [
{
path: '/',
route: HomePage.model.route,
},
],
});

export const RoutesView = createRoutesView({
routes: [
{
route: HomePage.model.route,
view: HomePage.ui.PageView,
},
],
});
7 changes: 7 additions & 0 deletions apps/vite-react/src/pages/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as model from './model';
import * as ui from './ui';

export const HomePage = {
model,
ui,
};
3 changes: 3 additions & 0 deletions apps/vite-react/src/pages/home/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createRoute } from 'atomic-router';

export const route = createRoute();
11 changes: 11 additions & 0 deletions apps/vite-react/src/pages/home/ui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Button } from '@my-org/react-ui/button';

export function PageView() {
return (
<div className="h-screen w-screen flex justify-center items-center gap-2">
<Button size="sm">Hello</Button>
<Button size="md">Hello</Button>
<Button size="lg">Hello</Button>
</div>
);
}
File renamed without changes.
1 change: 1 addition & 0 deletions apps/vite-react/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
3 changes: 3 additions & 0 deletions apps/vite-react/tailwind.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createTailwindConfig } = require('@my-org/config/tailwind');

module.exports = createTailwindConfig(__dirname);
8 changes: 8 additions & 0 deletions apps/vite-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "vitest"]
},
"include": ["src"]
}
7 changes: 7 additions & 0 deletions apps/vite-react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
plugins: [react(), tsconfigPaths()],
});

0 comments on commit 7111860

Please sign in to comment.