1. Cấu hình啟 động project và tự động mở trình duyệt
Trong file package.json:
"scripts": {
"dev": "vite --open",
"build": "vue-tsc && vite build",
"preview": "vite preview",
"lint": "eslint src",
"fix": "eslint src --fix",
"format": "prettier --write \"./**/*.{html,vue,ts,json,md}\"",
"lint:eslit": "eslint src/**/*.{ts,vue} --cache --fix",
"lint:style": "stylelint src/**/*.{css,scss,vue} --cache --fix",
},
2. Cấu hình công cụ kiểm tra mã nguồn ESLint
Thực hiện các bước sau:
- Đầu tiên, cài đặt ESLint:
pnpm i eslint -D
npx eslint --init
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
jest: true,
},
parser: 'vue-eslint-parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: '@typescript-eslint/parser',
jsxPragma: 'React',
ecmaFeatures: {
jsx: true,
}
},
extends: [
'eslint:recommended',
'plugin:vue/vue3-essential',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
plugins: ['vue', '@typescript-eslint'],
rules: {
'no-var': 'error',
'no-multiple-empty-lines': ['warn', { max: 1 }],
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'optional',
'no-useless-escape': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/semi': 'off',
'vue/multi-word-component-names': 'off',
'vue/script-setup-uses-vars': 'error',
'vue/no-mutating-props': 'off',
'vue/attribute-hyphenation': 'off',
}
}
dist
node_modules
"scripts": {
"lint": "eslint src",
"fix": "eslint src --fix",
},
3. Cấu hình công cụ định dạng mã nguồn Prettier
- Cài đặt các phụ thuộc:
pnpm install -D eslint-plugin-prettier eslint-config-prettier
{
"singleQuote": true,
"semi": false,
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"endOfLine": "auto",
"trailingComma": "all",
"tabWidth": 2
}
/dist/*
/html/*
.local
/node_modules/**
**/*.svg
**/*.sh
/public/*
4. Cấu hình công cụ kiểm tra CSS Stylelint
- Cài đặt các phụ thuộc cần thiết:
pnpm add sass sass-loader stylelint postcss postcss-scss postcss-html stylelint-config-prettier stylelint-config-recess-order stylelint-config-recommended-scss stylelint-config-standard stylelint-config-standard-vue stylelint-scss stylelint-order stylelint-config-standard-scss -D
module.exports = {
extends: [
'stylelint-config-standard',
'stylelint-config-html/vue',
'stylelint-config-standard-scss',
'stylelint-config-recess-order',
'stylelint-config-prettier',
],
overrides: [
{
files: ['**/*.(scss|css|vue|html)'],
customSyntax: 'postcss-scss',
},
{
files: ['**/*.(html|vue)'],
customSyntax: 'postcss-html',
}
],
ignoreFiles: [
'**/*.js',
'**/*.jsx',
'**/*.tsx',
'**/*.ts',
'**/*.json',
'**/*.md',
'**/*.yaml',
],
rules: {
'value-keyword-case': null,
'no-descending-specificity': null,
'function-url-quotes': 'always',
'no-empty-source': null,
'selector-class-pattern': null,
'property-no-unknown': null,
'block-opening-brace-space-before': 'always',
'value-no-vendor-prefix': null,
'property-no-vendor-prefix': null,
'selector-pseudo-class-no-unknow': [
true,
{
ignorePseudoClasses: ['global', 'v-deep', 'deep'],
}
]
}
}
/node_modules/*
/dist/*
/html/*
/public/*
"scripts": {
"lint:style": "stylelint src/**/*.{css,scss,vue} --cache --fix"
}
5. Cấu hình Husky để kiểm tra trước khi commit
- Cài đặt Husky:
pnpm install -D husky
pnpm run prepare
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pnpm run format
6. Cấu hình CommitLint cho project
Đang trong quá trình cấu hình...