Configs
Prettier
npm install --save-dev --save-exact prettier prettier-plugin-tailwindcss
.prettierrc
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"bracketSpacing": true,
"printWidth": 80,
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindFunctions": ["clsx", "cn", "cva"],
"overrides": [
{
"files": ["framework/saleor/**/*"],
"options": {
"printWidth": 120
}
}
]
}
Eslint
Ở .eslintrc.js
: extends
dùng các config-name
dc lấy từ các eslint-config-<config-name>
trong file package.json
Sự khác nhau giữa extends
và plugins
: plugins
phải tự add rules vào, extends
là tổng hợp các configs sẵn.
- Install
- .eslintrc.js React
- eslint.config.js React (Eslint v9+)
- .eslintrc.js Vue
npm i eslint eslint-plugin-react eslint-plugin-react-hooks eslint-config-prettier -D
npm init @eslint/config
npm i @typescript-eslint/eslint-plugin @typescript-eslint/parser -D
npm i eslint-config-next -D
module.exports = {
env: {
es2021: true,
node: true,
},
plugins: ['react', '@typescript-eslint'],
parser: '@typescript-eslint/parser', // only for ts
extends: [
'eslint:recommended',
'plugin:react/recommended', // from eslint-plugin-react
'plugin:react/jsx-runtime', // from eslint-plugin-react
'plugin:react-hooks/recommended', // from eslint-plugin-react-hooks
'plugin:@typescript-eslint/recommended', // only for ts
'next', // from eslint-config-next
'prettier', // put this last so it can override other configs
],
rules: {
'react/prop-types': 'off',
'react/jsx-no-target-blank': 'off',
'react/no-unescaped-entities': 'off',
'no-unused-vars': 'off',
'no-undef': 'off', // only for ts
'@typescript-eslint/no-unused-vars': 'off', // only for ts
'@typescript-eslint/no-explicit-any': 'off', // only for ts
},
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 'latest',
sourceType: 'module',
},
}
// If not work change the suffix from ".js" to ".cjs"
[Doc](https://eslint.org/docs/latest/use/configure/configuration-files-new#using-plugins-in-your-configuration)
import react from 'eslint-plugin-react'
import next from '@next/eslint-plugin-next'
import js from '@eslint/js'
import markdown from 'eslint-plugin-markdown'
import { browser } from 'globals'
export default [
// js.configs.recommended predefined configuration is applied first before the two below
js.configs.recommended,
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
plugins: { react, next, js },
...react.configs.recommended,
...next.configs.recommended,
languageOptions: {
parserOptions: { ecmaFeatures: { jsx: true } },
globals: { ...browser },
},
rules: {
'react/prop-types': 'off',
'react/no-unescaped-entities': 'off',
'no-unused-vars': 'off',
},
},
{
files: ['**/*.md'],
plugins: { markdown },
processor: 'markdown/markdown',
},
]
module.exports = {
env: {
es2021: true,
node: true,
},
extends: ['eslint:recommended', 'prettier'],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-unused-vars': 'off',
'vue/multi-word-component-names': 'off',
},
}
tsconfig.json (or jsconfig.json)
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"baseUrl": ".", // hoặc "src", depends on project structure
"paths": {
// Cách 1: @/components/...; @/lib/...
"@/*": ["*"],
// Cách 2: @components/...; @lib/...
"@components/*": ["components/*"],
"@lib/*": ["lib/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["src/stories/**/*"] /* Exclude stories from build */
}
Tailwind
tailwind.config.js
module.exports = {
theme: {
extend: {
screens: {
'2xl': '1440px', // Replace the value of `2xl`
'3xl': '1600px', // Adds a new `3xl:` screen variant
},
// These values are inherited by the padding, margin, width, height, maxHeight, flex-basis, gap, inset, space, translate, scrollMargin, scrollPadding, and textIndent core plugins.
spacing: {
px: '1px',
18: '4.5rem',
},
fontSize: {
base: ['16px', '20px'], // font size 16px & line height 20px
},
},
// No `extend`: All default configuration for that key will be overwritten, e.g. in this case no more `text-red-500`...
colors: {
primary: {
DEFAULT: '#FF5A5F',
500: '#F47920',
900: '#FEE6D3',
},
},
},
}
index.css
Order: base
→ components
→ utilities
→ Our custom CSS.
The reason to use @layer
is that we can use modifiers e.g. dark
, responsive like lg
, hover
,...
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
h1,
.h1 {
@apply text-[40px] -tracking-[0.03em] lg:text-[64px] lg:leading-[72px];
}
}
@layer components {
.btn-primary {
@apply bg-blue-500 hover:bg-blue-700 dark:bg-blue-400 dark:hover:bg-blue-600;
}
}
@layer utilities {
.filter-none {
filter: none;
}
}
.our-layout {
padding-left: max(24px, calc((100vw - 1152px) / 2));
padding-right: max(24px, calc((100vw - 1152px) / 2));
}
VSCode
- Monolisa
- .vscode/tasks.json
{
,"editor.fontFamily": "monolisa",
"editor.fontWeight": "400",
"editor.fontSize": 12,
"editor.lineHeight": 1.4
}
{
"version": "2.0.0",
"tasks": [
{
"label": "git add .",
"type": "shell",
"command": "git add ."
},
{
"label": "git commit --amend --no-edit",
"type": "shell",
"command": "git commit --amend --no-edit",
"dependsOn": ["git add ."],
"dependsOrder": "sequence"
},
{
"label": "Amend",
"type": "shell",
"command": "git push --force",
"dependsOn": ["git commit --amend --no-edit"],
"dependsOrder": "sequence"
}
]
}
Node version manager
nvm install 14
nvm use 14.19.3
nvm list
nvm use newest
node -v
Update all dependencies
npm i -g npm-check-updates
ncu -i --format group --target minor
# "react-..."
ncu -i --format group react-*
Install beta (or alpha, rc) version
npm view package-name dist-tags // { latest: '1.0.0', beta: '1.0.1-beta.0',... }
package.json
{
"dependencies": {
"package-name": "beta"
}
}
npm, npx, yarn
- package.json: ~1.2.3 < 1.3.0 || ^1.2.3 < 2.0.0
npm i
/npm i -g
: Project Dependencies / Global Dependencies.npm i [--save-dev / -D]
: Development Only (devDependencies
) → Không có trong Production.npx
: Chỉ execute chứ ko cài → Dùng cho các lib chỉ chạy 1 lần trong vòng đời dự án nhưcreate-react-app
.yarn
: Chạy song song + cached so với Chạy tuần tự + ko cached củanpm
.
Husky & lint-staged
- Install
- package.json
- .husky/pre-commit
npm install husky --save-dev
npm set-script prepare "husky install"
npm run prepare
npx husky add .husky/pre-commit "npx --no-install lint-staged"
git add .husky/pre-commit
npm install --save-dev lint-staged
{
"devDependencies": {
"husky": "^8.0.1",
"lint-staged": "^13.0.3"
},
"lint-staged": {
"*.+(js|jsx|ts|tsx)": ["eslint --fix"],
"*.+(js|jsx|ts|tsx|json|css|md|mdx)": ["prettier --write"]
}
}
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install lint-staged