React Scaffolding Instructions
Scaffold the react project using vite
npm create vite@latest- Name your project
- Choose
react - Choose
Typescript(the default)
Open the project in VS Code.
cd <project-name>
code .Open a terminal
# install dependencies
npm iAdd the the current LTS versions of Node and npm to the package.json file. Use the current LTS version instead of the settings below.
"engines": {
"npm": ">=10.0.0",
"node": ">=20.0.0"
},- Install eslint-plugin-react
npm i --save-dev eslint-plugin-react- Add the following lines to the
extendslist in the.eslint.cjsfile
// other extends
'plugin:react/recommended',
'plugin:react/jsx-runtime'- Add the following
settingssection to the.eslint.cjsfile
settings: {
react: {
version: 'detect',
},
},npm i --save-dev prettier
# Configure
echo "{ \"singleQuote\": true }" > .prettierrc
Add ignore file
touch .prettierignoreAdd the following lines
# Ignore artifacts
dist
coverage- eslintrc: Add "prettier" to the "extends" array in your .eslintrc.* file. Make sure to put it last, so it gets the chance to override other configs.
// other extends
"prettier"Format all files
npx prettier . --writenpm install --save-dev husky
# Configure
npx husky initnpm install --save-dev @commitlint/config-conventional @commitlint/cli
# Configure
echo "{ extends: ['@commitlint/config-conventional'] }" > .commitlintrc
# Add commit message linting to commit-msg hook
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msgnpm install --save-dev lint-staged
# Configure
echo "{'src/**/*.{ts,tsx}': ['npm run lint']}" > .lintstagedrcAdd husky hook to .husky/pre-commit
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- lint-staged --quietConfigure relative paths
/* Paths */
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
- Import path (top of the file)
import path from 'path;- Add the following lines to
defineConfig
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
- Execute
Preferences: Open Workspace Settings (JSON)from the vs code command palette
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.importModuleSpecifier": "non-relative",
"editor.formatOnSave": true
Create the extensions.json
touch .vscode/extensions.jsonThen paste the following lines in the extensions.json file.
{
"recommendations": [
"mikestead.dotenv",
"dsznajder.es7-react-js-snippets",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"christian-kohler.path-intellisense"
]
}Add the project to git specifying main as the master branch
git init -b mainDelete following lines from the generated .gitignore
.vscode/*
!.vscode/extensions.json