Appearance
项目配置
tailwindcss
init
sh
pnpm add -D tailwindcss@latest postcss@latest autoprefixer@latest
npx tailwindcss init -p
config
ts
// main.ts
import "tailwindcss/tailwind.css";
commitlint
pnpm add -D @commitlint/cli @commitlint/config-conventional
添加 husky
npx husky-init && pnpm install
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
添加 commitlint.config.js
js
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [
2,
"always",
[
"init",
"build",
"ci",
"docs",
"fix",
"perf",
"feat",
"style",
"refactor",
"test",
"revert",
"chore",
"wip",
],
],
"subject-full-stop": [0, "never"],
"subject-case": [0, "never"],
},
};
eslint
sh
pnpm add -D eslint
./node_modules/.bin/eslint --init
You can also run this command directly using 'npm init @eslint/config'.
npx: 40 安装成功,用时 23.994 秒
✔ How would you like to use ESLint? · style
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · vue
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ How would you like to define a style for your project? · guide
✔ Which style guide do you want to follow? · standard
✔ What format do you want your config file to be in? · JavaScript
Checking peerDependencies of eslint-config-standard@latest
✔ The style guide "standard" requires eslint@^7.12.1. You are currently using eslint@8.11.0.
Do you want to downgrade? · No / Yes
The config that you've selected requires the following dependencies:
eslint-plugin-vue@latest @typescript-eslint/eslint-plugin@latest eslint-config-standard@latest eslint@^7.12.1 eslint-plugin-import@^2.22.1 eslint-plugin-node@^11.1.0 eslint-plugin-promise@^4.2.1 || ^5.0.0 @typescript-eslint/parser@latest
✔ Would you like to install them now with npm? · No / Yes
A config file was generated, but the config file itself may not follow your linting rules.
Successfully created .eslintrc.js file in /Users/paul/Workspace/lab/@dcv/dcv_next
依赖
sh
pnpm add -D eslint-plugin-vue@latest prettier eslint-config-prettier eslint-plugin-prettier @typescript-eslint/parser eslint-define-config
.eslintrc.js
js
// @ts-check
const { defineConfig } = require("eslint-define-config");
module.exports = defineConfig({
root: true,
env: {
browser: true,
node: true,
es6: true,
},
parser: "vue-eslint-parser",
parserOptions: {
parser: "@typescript-eslint/parser",
ecmaVersion: 2020,
sourceType: "module",
jsxPragma: "React",
ecmaFeatures: {
jsx: true,
},
},
extends: [
"plugin:vue/vue3-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended",
],
rules: {
"vue/script-setup-uses-vars": "error",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"vue/custom-event-name-casing": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"space-before-function-paren": "off",
"vue/attributes-order": "off",
"vue/v-on-event-hyphenation": "off",
"vue/multi-word-component-names": "off",
"vue/one-component-per-file": "off",
"vue/html-closing-bracket-newline": "off",
"vue/max-attributes-per-line": "off",
"vue/multiline-html-element-content-newline": "off",
"vue/singleline-html-element-content-newline": "off",
"vue/attribute-hyphenation": "off",
"vue/require-default-prop": "off",
"vue/html-self-closing": [
"error",
{
html: {
void: "always",
normal: "never",
component: "always",
},
svg: "always",
math: "always",
},
],
},
});
add script
json
"lint:eslint": "eslint --cache --max-warnings 0 \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
changelog
sh
pnpm add -D conventional-changelog-cli
json
"version": "conventional-changelog -p angular -i CHANGELOG.md -s"
stylelint
pnpm add -D stylelint stylelint-config-standard stylelint-order postcss-html
sh
touch stylelint.config.js
js
module.exports = {
root: true,
plugins: ["stylelint-order"],
customSyntax: "postcss-html",
extends: ["stylelint-config-standard", "stylelint-config-prettier"],
rules: {
"selector-class-pattern": null,
"selector-pseudo-class-no-unknown": [
true,
{
ignorePseudoClasses: ["global"],
},
],
"selector-pseudo-element-no-unknown": [
true,
{
ignorePseudoElements: ["v-deep"],
},
],
"at-rule-no-unknown": [
true,
{
ignoreAtRules: [
"tailwind",
"apply",
"variants",
"responsive",
"screen",
"function",
"if",
"each",
"include",
"mixin",
],
},
],
"no-empty-source": null,
"named-grid-areas-no-invalid": null,
"unicode-bom": "never",
"no-descending-specificity": null,
"font-family-no-missing-generic-family-keyword": null,
"declaration-colon-space-after": "always-single-line",
"declaration-colon-space-before": "never",
// 'declaration-block-trailing-semicolon': 'always',
"rule-empty-line-before": [
"always",
{
ignore: ["after-comment", "first-nested"],
},
],
"unit-no-unknown": [true, { ignoreUnits: ["rpx"] }],
"order/order": [
[
"dollar-variables",
"custom-properties",
"at-rules",
"declarations",
{
type: "at-rule",
name: "supports",
},
{
type: "at-rule",
name: "media",
},
"rules",
],
{ severity: "warning" },
],
},
ignoreFiles: ["**/*.js", "**/*.jsx", "**/*.tsx", "**/*.ts"],
overrides: [
{
files: ["*.vue", "**/*.vue"],
extends: ["stylelint-config-recommended", "stylelint-config-html"],
rules: {
"selector-pseudo-class-no-unknown": [
true,
{
ignorePseudoClasses: ["deep", "global"],
},
],
"selector-pseudo-element-no-unknown": [
true,
{
ignorePseudoElements: ["v-deep", "v-global", "v-slotted"],
},
],
},
},
],
};
json
"lint:css":"stylelint --cache --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/"
pretty-quick
Runs Prettier on your changed files.
pnpm add -D pretty-quick
json
"lint:pretty": "pretty-quick --staged",
lint-staged
lint staged file
pnpm add -D lint-staged
json
"lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
自定义 lintstagedrc 配置
js
module.exports = {
"*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
"{!(package)*.json,*.code-snippets,.!(browserslist)*rc}": [
"prettier --write--parser json",
],
"package.json": ["prettier --write"],
"*.vue": ["eslint --fix", "prettier --write", "stylelint --fix"],
"*.{scss,less,styl}": ["stylelint --fix", "prettier --write"],
"*.md": ["prettier --write"],
};