React Development Guide

Tooling Guide

EditorConfig Code Style

EditorConfig Guide

# SPDX-FileCopyrightText: None
#
# SPDX-License-Identifier: 0BSD

[*.html]
indent_size = 2
tab_width = 2

[{*.js,*.jsx}]
indent_size = 2
tab_width = 2
ij_continuation_indent_size = 4
ij_javascript_enforce_trailing_comma = whenmultiline

[*.json]
indent_size = 2
#indent_style = space

[{*.yml,*.yaml}]
indent_size = 2
#indent_style = space

[package.json]
# Tooling uses 2-space indentation; match it.
indent_size = 2
indent_style = space

Exclude Files from Version Tracking

Git Repository Guide

# SPDX-FileCopyrightText: None
#
# SPDX-License-Identifier: 0BSD

.yarn/*
!.yarn/cache/
!.yarn/releases/
yarn-debug.log*
yarn-error.log*
/node_modules/

Initialize React Project with Vite

documentation documentation

Create a New Project

documentation documentation

export VITE_PROJECT="vite-project"
yarn create vite -t react --no-interactive "$VITE_PROJECT"

Cleanup Vite Project Template

yarn install --immutable --immutable-cache
yarn remove @types/react @types/react-dom
yarn remove oxlint
rm .oxlintrc.json
sed -i '/"lint":/d' package.json
sed -i 's@/src/main.jsx@/app/main.jsx@' index.html
mv src app

Setup Custom Import Aliases

documentation

{
  "imports": {
    "#app/": "./app/",
    "#assets/": "./assets/",
    "#lib/": "./lib/",
    "#routes/": "./routes/"
  }
}

Use Latest Version of Yarn

documentation documentation

yarn set version stable
yarn install

Enable Node Modules Linking with Local Cache

# SPDX-FileCopyrightText: None
#
# SPDX-License-Identifier: 0BSD

enableGlobalCache: false

# [!] NPM Supply Chain Attack Mitigation.
enableScripts: false

enableTelemetry: false

nodeLinker: node-modules
# SPDX-FileCopyrightText: None
#
# SPDX-License-Identifier: 0BSD

.yarn/*
!.yarn/cache/
!.yarn/releases/
yarn-debug.log*
yarn-error.log*
/node_modules/

Unify Chores via Makefile

# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: 0BSD

JQ := $(shell command -v jq 2>/dev/null)
ifeq ($(JQ),)
$(error jq is required but not installed)
endif

DISTNAME := $(shell jq -r .name package.json)
VERSION := $(shell jq -r .version package.json)
DISTDIR := dist

HOST := 127.27.0.1
PORT := 5173

.PHONY: dev
dev:
	yarn dev --host="$(HOST)" --port="$(PORT)"

.PHONY: install
install:
	yarn install --immutable --immutable-cache

.PHONY: update
update:
	yarn up

.PHONY: build
build:
	yarn build --outDir="$(DISTDIR)"

.PHONY: dist
dist: build
	tar --directory="$(DISTDIR)" --create --xz --file="$(DISTNAME)-$(VERSION).tar.xz" .

.PHONY: test
test:
	yarn test

.PHONY: clean
clean:
	-rm --recursive "$(DISTDIR)"
	-rm "$(DISTNAME)-$(VERSION).tar.xz"

.PHONY: distclean
distclean: clean
	git clean --force -Xd

Install and Setup Tailwind CSS

documentation documentation

yarn add --dev tailwindcss @tailwindcss/vite
// SPDX-FileCopyrightText: None
// SPDX-License-Identifier: 0BSD

import {defineConfig} from 'vite'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [
    tailwindcss(),
  ],
})
@import "tailwindcss";

Install and Setup Vitest Framework

documentation documentation

yarn add --dev vitest jsdom @testing-library/dom @testing-library/jest-dom @testing-library/react
// SPDX-FileCopyrightText: None
// SPDX-License-Identifier: 0BSD

import {defineConfig} from 'vite'

export default defineConfig({
  test: {
    environment: 'jsdom',
    globals: true,
    isolate: true,
    mockReset: true,
    restoreMocks: true,
    setupFiles: './tests/setupTests.js',
  },
})
// SPDX-FileCopyrightText: None
// SPDX-License-Identifier: 0BSD

import '@testing-library/jest-dom'
{
  "scripts": {
    "test": "vitest"
  }
}

Base UI Component Library

The Base_UI_Project documentation mui/base-ui

Installing Base UI

yarn add @base-ui/react