Skip to content

Commit

Permalink
react-app tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacplmann committed May 31, 2024
1 parent 25be6d5 commit c8fd1aa
Show file tree
Hide file tree
Showing 61 changed files with 13,657 additions and 0 deletions.
34 changes: 34 additions & 0 deletions react-app/.eslintrc.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
}
]
}
32 changes: 32 additions & 0 deletions react-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'./.eslintrc.base.json',
],
ignorePatterns: ['!**/*', 'node_modules', 'dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
{
files: ['*.ts', '*.tsx'],
rules: {},
},
{
files: ['*.js', '*.jsx'],
rules: {},
},
],
};
36 changes: 36 additions & 0 deletions react-app/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches:
- main
pull_request:

permissions:
actions: read
contents: read

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"

# Cache node_modules
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'

- run: npm ci
- uses: nrwl/nx-set-shas@v4

# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: npx nx-cloud record -- echo Hello World
- run: npx nx affected -t lint test build
27 changes: 27 additions & 0 deletions react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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?


.nx/cache
4 changes: 4 additions & 0 deletions react-app/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/.nx/cache
3 changes: 3 additions & 0 deletions react-app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
20 changes: 20 additions & 0 deletions react-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Tutorial: Standalone React Application

[![standalone application](https://img.shields.io/static/v1?label=Nx%20setup&message=standalone%20app&color=blue)](https://nx.dev/concepts/integrated-vs-package-based#standalone-applications)

Source code for the React standalone application tutorial on the Nx docs:
- Tutorial: https://nx.dev/getting-started/react-standalone-tutorial

## What's inside?

This example contains a single Vite-based React application that has been generated with the `npm create vite` command. It contains a single root-level application and local libraries within the `modules` folder.

Follow through the tutorial linked above for more details.

## How to run it

Install all dependencies using `npm install`. You can then run commands Like

- `npx nx serve` to serve the app
- `npx nx build` to build the React application
- you can use `npx nx graph` to visualize the structure
13 changes: 13 additions & 0 deletions react-app/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>
12 changes: 12 additions & 0 deletions react-app/modules/orders/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions react-app/modules/orders/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions react-app/modules/orders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# orders

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test orders` to execute the unit tests via [Vitest](https://vitest.dev/).
9 changes: 9 additions & 0 deletions react-app/modules/orders/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "orders",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "modules/orders/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project orders --web",
"targets": {}
}
1 change: 1 addition & 0 deletions react-app/modules/orders/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/orders';
7 changes: 7 additions & 0 deletions react-app/modules/orders/src/lib/orders.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Replace this with your own classes
*
* e.g.
* .container {
* }
*/
10 changes: 10 additions & 0 deletions react-app/modules/orders/src/lib/orders.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render } from '@testing-library/react';

import Orders from './orders';

describe('Orders', () => {
it('should render successfully', () => {
const { baseElement } = render(<Orders />);
expect(baseElement).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions react-app/modules/orders/src/lib/orders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styles from './orders.module.css';

/* eslint-disable-next-line */
export interface OrdersProps {}

export function Orders() {
return (
<div className={styles['container']}>
<h1>Welcome to Orders!</h1>
</div>
);
}

export default Orders;
20 changes: 20 additions & 0 deletions react-app/modules/orders/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
}
23 changes: 23 additions & 0 deletions react-app/modules/orders/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"node",

"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"exclude": [
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
26 changes: 26 additions & 0 deletions react-app/modules/orders/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]
},
"include": [
"vite.config.ts",
"vitest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
27 changes: 27 additions & 0 deletions react-app/modules/orders/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/modules/orders',

plugins: [react(), nxViteTsPaths()],

// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },

test: {
globals: true,
cache: { dir: '../../node_modules/.vitest/modules/orders' },
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../../coverage/modules/orders',
provider: 'v8',
},
},
});
12 changes: 12 additions & 0 deletions react-app/modules/products/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions react-app/modules/products/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading

0 comments on commit c8fd1aa

Please sign in to comment.