my-cli-vue-template-demo2 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/lib/create.js +2 -2
  2. package/package.json +2 -2
  3. package/templates/vue-ts-vite-taillwind-template/.editorconfig +12 -0
  4. package/templates/vue-ts-vite-taillwind-template/.gitattributes +1 -0
  5. package/templates/vue-ts-vite-taillwind-template/.husky/commit-msg +1 -0
  6. package/templates/vue-ts-vite-taillwind-template/.husky/pre-commit +4 -0
  7. package/templates/vue-ts-vite-taillwind-template/.prettierignore +10 -0
  8. package/templates/vue-ts-vite-taillwind-template/.prettierrc.cjs +40 -0
  9. package/templates/vue-ts-vite-taillwind-template/.stylelintignore +4 -0
  10. package/templates/vue-ts-vite-taillwind-template/.stylelintrc.cjs +37 -0
  11. package/templates/vue-ts-vite-taillwind-template/.vscode/extensions.json +21 -0
  12. package/templates/vue-ts-vite-taillwind-template/.vscode/settings.json +167 -0
  13. package/templates/vue-ts-vite-taillwind-template/README.md +186 -0
  14. package/templates/vue-ts-vite-taillwind-template/commitlint.config.cjs +101 -0
  15. package/templates/vue-ts-vite-taillwind-template/env.d.ts +1 -0
  16. package/templates/vue-ts-vite-taillwind-template/eslint.config.mjs +31 -0
  17. package/templates/vue-ts-vite-taillwind-template/index.html +13 -0
  18. package/templates/vue-ts-vite-taillwind-template/lint-staged.config.cjs +7 -0
  19. package/templates/vue-ts-vite-taillwind-template/package-lock.json +11398 -0
  20. package/templates/vue-ts-vite-taillwind-template/package.json +79 -0
  21. package/templates/vue-ts-vite-taillwind-template/pnpm-lock.yaml +7206 -0
  22. package/templates/vue-ts-vite-taillwind-template/public/favicon.ico +0 -0
  23. package/templates/vue-ts-vite-taillwind-template/src/App.vue +91 -0
  24. package/templates/vue-ts-vite-taillwind-template/src/assets/base.css +79 -0
  25. package/templates/vue-ts-vite-taillwind-template/src/assets/logo.svg +1 -0
  26. package/templates/vue-ts-vite-taillwind-template/src/assets/main.css +40 -0
  27. package/templates/vue-ts-vite-taillwind-template/src/assets/theme.css +28 -0
  28. package/templates/vue-ts-vite-taillwind-template/src/components/HelloWorld.vue +47 -0
  29. package/templates/vue-ts-vite-taillwind-template/src/components/TheWelcome.vue +90 -0
  30. package/templates/vue-ts-vite-taillwind-template/src/components/ThemeToggle.vue +31 -0
  31. package/templates/vue-ts-vite-taillwind-template/src/components/WelcomeItem.vue +86 -0
  32. package/templates/vue-ts-vite-taillwind-template/src/components/icons/IconCommunity.vue +7 -0
  33. package/templates/vue-ts-vite-taillwind-template/src/components/icons/IconDocumentation.vue +7 -0
  34. package/templates/vue-ts-vite-taillwind-template/src/components/icons/IconEcosystem.vue +7 -0
  35. package/templates/vue-ts-vite-taillwind-template/src/components/icons/IconSupport.vue +7 -0
  36. package/templates/vue-ts-vite-taillwind-template/src/components/icons/IconTooling.vue +19 -0
  37. package/templates/vue-ts-vite-taillwind-template/src/main.ts +14 -0
  38. package/templates/vue-ts-vite-taillwind-template/src/router/index.ts +23 -0
  39. package/templates/vue-ts-vite-taillwind-template/src/stores/counter.ts +12 -0
  40. package/templates/vue-ts-vite-taillwind-template/src/stores/test.css +20 -0
  41. package/templates/vue-ts-vite-taillwind-template/src/stores/test.ts +15 -0
  42. package/templates/vue-ts-vite-taillwind-template/src/views/AboutView.vue +16 -0
  43. package/templates/vue-ts-vite-taillwind-template/src/views/HomeView.vue +9 -0
  44. package/templates/vue-ts-vite-taillwind-template/tailwind.config.ts +12 -0
  45. package/templates/vue-ts-vite-taillwind-template/tsconfig.app.json +12 -0
  46. package/templates/vue-ts-vite-taillwind-template/tsconfig.json +11 -0
  47. package/templates/vue-ts-vite-taillwind-template/tsconfig.node.json +19 -0
  48. package/templates/vue-ts-vite-taillwind-template/vite.config.ts +16 -0
  49. package/templates/vue-ts-vite-template/.editorconfig +12 -0
  50. package/templates/vue-ts-vite-template/.gitattributes +1 -0
  51. package/templates/vue-ts-vite-template/.husky/commit-msg +1 -0
  52. package/templates/vue-ts-vite-template/.husky/pre-commit +4 -0
  53. package/templates/vue-ts-vite-template/.prettierignore +10 -0
  54. package/templates/vue-ts-vite-template/.prettierrc.cjs +40 -0
  55. package/templates/vue-ts-vite-template/.stylelintignore +4 -0
  56. package/templates/vue-ts-vite-template/.stylelintrc.cjs +37 -0
  57. package/templates/vue-ts-vite-template/.vscode/extensions.json +20 -0
  58. package/templates/vue-ts-vite-template/.vscode/settings.json +155 -0
  59. package/templates/vue-ts-vite-template/README.md +186 -0
  60. package/templates/vue-ts-vite-template/commitlint.config.cjs +101 -0
  61. package/templates/vue-ts-vite-template/env.d.ts +1 -0
  62. package/templates/vue-ts-vite-template/eslint.config.mjs +31 -0
  63. package/templates/vue-ts-vite-template/index.html +13 -0
  64. package/templates/vue-ts-vite-template/lint-staged.config.cjs +7 -0
  65. package/templates/vue-ts-vite-template/package-lock.json +10959 -0
  66. package/templates/vue-ts-vite-template/package.json +76 -0
  67. package/templates/vue-ts-vite-template/pnpm-lock.yaml +6879 -0
  68. package/templates/vue-ts-vite-template/public/favicon.ico +0 -0
  69. package/templates/vue-ts-vite-template/src/App.vue +87 -0
  70. package/templates/vue-ts-vite-template/src/assets/base.css +79 -0
  71. package/templates/vue-ts-vite-template/src/assets/logo.svg +1 -0
  72. package/templates/vue-ts-vite-template/src/assets/main.css +35 -0
  73. package/templates/vue-ts-vite-template/src/components/HelloWorld.vue +47 -0
  74. package/templates/vue-ts-vite-template/src/components/TheWelcome.vue +90 -0
  75. package/templates/vue-ts-vite-template/src/components/WelcomeItem.vue +86 -0
  76. package/templates/vue-ts-vite-template/src/components/icons/IconCommunity.vue +7 -0
  77. package/templates/vue-ts-vite-template/src/components/icons/IconDocumentation.vue +7 -0
  78. package/templates/vue-ts-vite-template/src/components/icons/IconEcosystem.vue +7 -0
  79. package/templates/vue-ts-vite-template/src/components/icons/IconSupport.vue +7 -0
  80. package/templates/vue-ts-vite-template/src/components/icons/IconTooling.vue +19 -0
  81. package/templates/vue-ts-vite-template/src/main.ts +14 -0
  82. package/templates/vue-ts-vite-template/src/router/index.ts +23 -0
  83. package/templates/vue-ts-vite-template/src/stores/counter.ts +12 -0
  84. package/templates/vue-ts-vite-template/src/stores/test.css +20 -0
  85. package/templates/vue-ts-vite-template/src/stores/test.ts +15 -0
  86. package/templates/vue-ts-vite-template/src/views/AboutView.vue +15 -0
  87. package/templates/vue-ts-vite-template/src/views/HomeView.vue +9 -0
  88. package/templates/vue-ts-vite-template/tsconfig.app.json +12 -0
  89. package/templates/vue-ts-vite-template/tsconfig.json +11 -0
  90. package/templates/vue-ts-vite-template/tsconfig.node.json +19 -0
  91. package/templates/vue-ts-vite-template/vite.config.ts +15 -0
  92. package/templates/vue-vite-template/index.js +0 -1
package/lib/create.js CHANGED
@@ -7,8 +7,8 @@ const ora = require('ora');
7
7
 
8
8
  // 模拟可选的模板列表,实际可以是远程 git 地址或本地路径
9
9
  const templates = [
10
- { name: 'Vue3 + Vite', value: 'vue-vite-template' },
11
- { name: 'React + Vite', value: 'react-vite-template' },
10
+ { name: 'Vue3 + Vite + TypeScript', value: 'vue-ts-vite-template' },
11
+ { name: 'Vue3 + Vite + TypeScript + TailwindCSS', value: 'vue-ts-vite-taillwind-template' },
12
12
  // 也可以是本地模板目录,比如 './templates/vue-basic'
13
13
  ];
14
14
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "my-cli-vue-template-demo2",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "模版测试",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "my-cli-vue-demo": "bin/cli.js"
7
+ "my-cli-vue": "bin/cli.js"
8
8
  },
9
9
  "directories": {
10
10
  "lib": "lib"
@@ -0,0 +1,12 @@
1
+ root = true
2
+ [*] # 表示所有文件适用
3
+ charset = utf-8 # 设置文件字符集为 utf-8
4
+ end_of_line = lf # 控制换行类型(lf | cr | crlf)
5
+ insert_final_newline = true # 始终在文件末尾插入一个新行
6
+ indent_style = space # 缩进风格(tab | space)
7
+ indent_size = 2 # 缩进大小
8
+ max_line_length = 120 # 最大行长度
9
+
10
+ [*.md] # 表示仅对 md 文件适用以下规则
11
+ max_line_length = off # 关闭最大行长度限制
12
+ trim_trailing_whitespace = false # 关闭末尾空格修剪
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1 @@
1
+ npx --no-install commitlint --edit "$1"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm run lint:lint-staged
@@ -0,0 +1,10 @@
1
+ # prettier 忽略文件
2
+ /dist/*
3
+ /build/*
4
+ /public/*
5
+
6
+ .local
7
+ /node_modules/**
8
+
9
+ **/*.svg
10
+ **/*.sh
@@ -0,0 +1,40 @@
1
+ // @see: https://www.prettier.cn
2
+ module.exports = {
3
+ // 指定最大换行长度
4
+ printWidth: 120,
5
+ // 缩进制表符宽度 | 空格数
6
+ tabWidth: 2,
7
+ // 使用制表符而不是空格缩进行 (true:制表符,false:空格)
8
+ useTabs: false,
9
+ // 结尾不用分号 (true:有,false:没有)
10
+ semi: false,
11
+ // 使用单引号 (true:单引号,false:双引号)
12
+ singleQuote: true,
13
+ // 在对象字面量中决定是否将属性名用引号括起来 可选值 "<as-needed|consistent|preserve>"
14
+ quoteProps: 'as-needed',
15
+ // 在JSX中使用单引号而不是双引号 (true:单引号,false:双引号)
16
+ jsxSingleQuote: false,
17
+ // 多行时尽可能打印尾随逗号 可选值"<none|es5|all>"
18
+ trailingComma: 'all',
19
+ // 在对象,数组括号与文字之间加空格 "{ foo: bar }" (true:有,false:没有)
20
+ bracketSpacing: true,
21
+ // 将 > 多行元素放在最后一行的末尾,而不是单独放在下一行 (true:放末尾,false:单独一行)
22
+ bracketSameLine: false,
23
+ // (x) => {} 箭头函数参数只有一个时是否要有小括号 (avoid:省略括号,always:不省略括号)
24
+ arrowParens: 'avoid',
25
+ // 指定要使用的解析器,不需要写文件开头的 @prettier
26
+ requirePragma: false,
27
+ // 可以在文件顶部插入一个特殊标记,指定该文件已使用 Prettier 格式化
28
+ insertPragma: false,
29
+ // 用于控制文本是否应该被换行以及如何进行换行
30
+ proseWrap: 'preserve',
31
+ // 在html中空格是否是敏感的 "css" - 遵守 CSS 显示属性的默认值, "strict" - 空格被认为是敏感的 ,"ignore" - 空格被认为是不敏感的
32
+ htmlWhitespaceSensitivity: 'css',
33
+ // 控制在 Vue 单文件组件中 <script> 和 <style> 标签内的代码缩进方式
34
+ vueIndentScriptAndStyle: false,
35
+ // 换行符使用 lf 结尾是 可选值 "<auto|lf|crlf|cr>"
36
+ endOfLine: 'auto',
37
+ // 这两个选项可用于格式化以给定字符偏移量(分别包括和不包括)开始和结束的代码 (rangeStart:开始,rangeEnd:结束)
38
+ rangeStart: 0,
39
+ rangeEnd: Infinity,
40
+ }
@@ -0,0 +1,4 @@
1
+ /dist/*
2
+ /public/*
3
+ public/*
4
+ node_modules/*
@@ -0,0 +1,37 @@
1
+ // @see: https://stylelint.io
2
+
3
+ module.exports = {
4
+ root: true,
5
+ // 继承某些已有的规则
6
+ extends: [
7
+ 'stylelint-config-standard', // 配置 stylelint 拓展插件
8
+ 'stylelint-config-html/vue', // 配置 vue 中 template 样式格式化
9
+ 'stylelint-config-standard-scss', // 配置 stylelint scss 插件
10
+ 'stylelint-config-recommended-vue/scss', // 配置 vue 中 scss 样式格式化
11
+ 'stylelint-config-recess-order', // 配置 stylelint css 属性书写顺序插件,
12
+ // "stylelint-config-prettier" // 配置 stylelint 和 prettier 兼容
13
+ ],
14
+ overrides: [
15
+ // 扫描 .vue/html 文件中的 <style> 标签内的样式
16
+ {
17
+ files: ['**/*.{vue,html}'],
18
+ customSyntax: 'postcss-html',
19
+ },
20
+ ],
21
+ rules: {
22
+ 'font-family-no-missing-generic-family-keyword': null, // 禁止在字体族名称列表中缺少通用字体族关键字
23
+ 'property-no-unknown': null, // 禁止未知的属性
24
+ 'no-empty-source': null, // 禁止空源码
25
+ 'selector-class-pattern': null, // 强制选择器类名的格式
26
+ 'value-no-vendor-prefix': null, // 关闭 vendor-prefix (为了解决多行省略 -webkit-box)
27
+ 'no-descending-specificity': null, // 不允许较低特异性的选择器出现在覆盖较高特异性的选择器
28
+ 'value-keyword-case': null, // 解决在 scss 中使用 v-bind 大写单词报错
29
+ 'selector-pseudo-class-no-unknown': [
30
+ true,
31
+ {
32
+ ignorePseudoClasses: ['global', 'v-deep', 'deep'],
33
+ },
34
+ ],
35
+ },
36
+ ignoreFiles: ['**/*.js', '**/*.jsx', '**/*.tsx', '**/*.ts'],
37
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "recommendations": [
3
+ "Vue.volar",
4
+ "Vue.vscode-typescript-vue-plugin",
5
+ "dbaeumer.vscode-eslint",
6
+ "EditorConfig.EditorConfig",
7
+ "esbenp.prettier-vscode",
8
+ "hollowtree.vue-snippets",
9
+ "stylelint.vscode-stylelint",
10
+ "streetsidesoftware.code-spell-checker",
11
+ "syler.sass-indented",
12
+ "mikestead.dotenv",
13
+ "formulahendry.auto-rename-tag",
14
+ "dsznajder.es7-react-js-snippets",
15
+ "vincaslt.highlight-matching-tag",
16
+ // "oderwat.indent-rainbow",
17
+ "techer.open-in-browser",
18
+ "ritwickdey.liveserver",
19
+ "bradlc.vscode-tailwindcss"
20
+ ]
21
+ }
@@ -0,0 +1,167 @@
1
+ {
2
+ // 让左侧的文件资源管理器(Explorer)更加整洁。它会将相关联的配置文件“折叠”在主配置文件下面
3
+ "explorer.fileNesting.enabled": true,
4
+ "explorer.fileNesting.patterns": {
5
+ "tsconfig.json": "tsconfig.*.json, env.d.ts",
6
+ "vite.config.*": "jsconfig*, vitest.config.*, cypress.config.*, playwright.config.*",
7
+ "package.json": "package-lock.json, pnpm*, .yarnrc*, yarn*, .eslint*, eslint*, .oxlint*, oxlint*, .prettier*, prettier*, .editorconfig, .stylelintrc*, .stylelintignore,commitlint.config*,lint-staged.config*,.gitignore,.gitattributes,tailwind.config*"
8
+ },
9
+ "editor.codeActionsOnSave": {
10
+ // 保存时自动修复错误
11
+ "source.fixAll": "explicit",
12
+ "source.fixAll.eslint": "explicit",
13
+ "source.fixAll.stylelint": "explicit"
14
+ },
15
+ // 保存时自动格式化,禁用它以避免与 ESLint 冲突
16
+ "editor.formatOnSave": true,
17
+ // 格式化时使用 Prettier
18
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
19
+ // CSS 代码检查工具
20
+ "stylelint.enable": true,
21
+ // 告诉 Stylelint 插件需要检查哪些类型的文件。
22
+ "stylelint.validate": ["css", "less", "postcss", "scss", "vue", "sass", "html"],
23
+ // Tab 键时的缩进宽度为 2 个空格
24
+ "editor.tabSize": 2,
25
+ // 混用换行符会导致 Git 提交记录混乱或某些工具报错。这个设置强制统一为 \n.保证跨平台一致性。
26
+ "files.eol": "\n",
27
+ // 指定哪些文件不参与搜索
28
+ "search.exclude": {
29
+ "**/node_modules": true,
30
+ "**/*.log": true,
31
+ "**/*.log*": true,
32
+ "**/bower_components": true,
33
+ "**/dist": true,
34
+ "**/elehukouben": true,
35
+ "**/.git": true,
36
+ "**/.gitignore": true,
37
+ "**/.svn": true,
38
+ "**/.DS_Store": true,
39
+ "**/.idea": true,
40
+ "**/.vscode": false,
41
+ "**/yarn.lock": true,
42
+ "**/tmp": true,
43
+ "out": true,
44
+ "dist": true,
45
+ "node_modules": true,
46
+ "CHANGELOG.md": true,
47
+ "examples": true,
48
+ "res": true,
49
+ "screenshots": true,
50
+ "yarn-error.log": true,
51
+ "**/.yarn": true
52
+ },
53
+ // 增强 Tailwind CSS 智能提示体验
54
+ "editor.quickSuggestions": {
55
+ "strings": true
56
+ },
57
+ // 强制 Vue 文件关联 :
58
+ "tailwindCSS.includeLanguages": {
59
+ "vue": "html"
60
+ },
61
+ // CSS 文件关联 :
62
+ "files.associations": {
63
+ "*.css": "tailwindcss"
64
+ },
65
+ // 指定哪些文件不被 VSCode 监听,预防启动 VSCode 时扫描的文件太多,
66
+ // 导致 CPU 占用过高
67
+ "files.watcherExclude": {
68
+ "**/.git/objects/**": true,
69
+ "**/.git/subtree-cache/**": true,
70
+ "**/.vscode/**": true,
71
+ "**/node_modules/**": true,
72
+ "**/tmp/**": true,
73
+ "**/bower_components/**": true,
74
+ "**/dist/**": true,
75
+ "**/yarn.lock": true
76
+ },
77
+ // 配置 VScode 使用 prettier 的 formatter
78
+ "[vue]": {
79
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
80
+ },
81
+ "[typescript]": {
82
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
83
+ },
84
+ "[json]": {
85
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
86
+ },
87
+ "[jsonc]": {
88
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
89
+ },
90
+ "[javascript]": {
91
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
92
+ },
93
+ "[typescriptreact]": {
94
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
95
+ },
96
+ "[scss]": {
97
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
98
+ },
99
+ "[html]": {
100
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
101
+ },
102
+ "[markdown]": {
103
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
104
+ },
105
+ "[less]": {
106
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
107
+ },
108
+ // 拼写错误忽略
109
+ "cSpell.words": [
110
+ "windi",
111
+ "browserslist",
112
+ "tailwindcss",
113
+ "esnext",
114
+ "axios",
115
+ "vuex",
116
+ "vueuse",
117
+ "antv",
118
+ "tinymce",
119
+ "qrcode",
120
+ "sider",
121
+ "pinia",
122
+ "sider",
123
+ "nprogress",
124
+ "INTLIFY",
125
+ "stylelint",
126
+ "esno",
127
+ "vitejs",
128
+ "sortablejs",
129
+ "mockjs",
130
+ "codemirror",
131
+ "iconify",
132
+ "commitlint",
133
+ "vditor",
134
+ "vite",
135
+ "echarts",
136
+ "cropperjs",
137
+ "logicflow",
138
+ "zxcvbn",
139
+ "lintstagedrc",
140
+ "brotli",
141
+ "tailwindcss",
142
+ "sider",
143
+ "pnpm",
144
+ "antd"
145
+ ],
146
+ "eslint.validate": [
147
+ "javascript",
148
+ "vue",
149
+ "vue-html",
150
+ "typescript",
151
+ "typescriptreact",
152
+ "html",
153
+ "css",
154
+ "scss",
155
+ "less",
156
+ "json",
157
+ "jsonc",
158
+ "json5",
159
+ "markdown"
160
+ ],
161
+ "eslint.rules.customizations": [
162
+ // 忽略所有规则
163
+ // { "rule": "*", "severity": "off" },
164
+ // 忽略 console
165
+ // { "rule": "no-console", "severity": "warn" }
166
+ ]
167
+ }
@@ -0,0 +1,186 @@
1
+ # 项目风格统一
2
+
3
+ ## .vscode
4
+
5
+ - extensions.json
6
+ - 设置需要安装什么插件
7
+ - settings.json
8
+ - 完善 settings.json 配置说明,解释每个设置项的作用和意义
9
+
10
+ ## .editorconfig
11
+
12
+ - 完善 .editorconfig 配置说明,解释每个设置项的作用和意义
13
+
14
+ ## 安装pnpm
15
+
16
+ - 安装pnpm包管理器
17
+
18
+ ## 代码格式化配置
19
+
20
+ - 安装prettier插件
21
+ - 下载相关依赖
22
+ - pnpm add prettier -D
23
+ - 配置.prettierrc文件
24
+ - 完善 .prettierrc 配置说明,解释每个设置项的作用和意义
25
+ - 配置.prettierignore文件
26
+ - 完善 .prettierignore 配置说明,解释每个设置项的作用和意义
27
+ - 添加脚本
28
+ - "lint:prettier": "prettier --write \"src/\*_/_.{js,ts,mjs,cjs,json,tsx,css,less,scss,vue,html,md}\""
29
+ - 运行脚本:pnpm run lint:prettier,就能看到乱的代码被格式化了。
30
+ - 代码格式化规范 ESLint
31
+ - <https://mp.weixin.qq.com/s?__biz=MzI2NTQ5NTE4OA==&mid=2247563610&idx=1&sn=3a3b2a61be32aa7f937f6d5027d8f666&chksm=ea9fcea1dde847b7b526014bc7ab311189e6ed6befdc078c3d36d62f09c20c781c6989450d84&scene=178&cur_album_id=4101027889775034373&search_click_id=#rd>
32
+ - Eslint9 推荐方式:<https://github.com/antfu/eslint-config>
33
+ - 使用开源的 eslint 配置仓库
34
+ - 安装依赖:pnpm i -D eslint @antfu/eslint-config
35
+ - 创建eslint.config.mjs文件
36
+ - 在package.json文件中处理脚本:"lint": "eslint .", "lint:fix": "eslint . --fix"
37
+ - 自己配置eslint
38
+ - 添加 eslint 的 vscode 配置:.vscode/settings.json
39
+ - 项目下载依赖:pnpm i eslint eslint-config-prettier eslint-plugin-prettier eslint-plugin-vue @typescript-eslint/eslint-plugin @typescript-eslint/parser -D
40
+ ![](https://cdn.jsdelivr.net/gh/aafyfhh/imagebase/content/img/20260126111605697.png)
41
+ - 配置 eslint 规则:.eslintrc.js
42
+ - 添加eslint 忽略文件:.eslintignore
43
+ - 添加eslint 脚本:package.json
44
+ - "lint:eslint": "eslint --fix --ext .js,.ts,.vue ./src",
45
+ - eslint这种编辑器行为是可以关闭的,尽管写,后面保存的时候统一格式化一下就好了。
46
+ - 通过在.vscode/settings.json文件中添加如下配置:
47
+ - "editor.codeActionsOnSave": {
48
+ "source.fixAll": "explicit",
49
+ "source.fixAll.eslint": "explicit"
50
+ },
51
+ - "eslint.rules.customizations": [
52
+ // 忽略所有规则
53
+ // { "rule": "*", "severity": "off" },
54
+ ]
55
+ - 查看 antfu/eslint-config 的配置规则
56
+ - 运行脚本:npx @eslint/config-inspector,访问<http://localhost:7777/>
57
+ - 自动修复错误(手动触发)
58
+ - 运行脚本:pnpm run lint:eslint --fix
59
+ - 保存文件也会自动修复错误:
60
+ - 配置.vscode/settings.json文件
61
+ - "source.fixAll": "explicit",
62
+ - "source.fixAll.eslint": "explicit"
63
+
64
+ ## css 规范 stylelint
65
+
66
+ - 安装 styleLint 插件
67
+ - 安装 stylelint 依赖
68
+ - pnpm install
69
+ stylelint
70
+ stylelint-config-html
71
+ stylelint-config-recommended-scss
72
+ stylelint-config-recommended-vue
73
+ stylelint-config-standard
74
+ stylelint-config-standard-scss
75
+ stylelint-config-recess-order
76
+ postcss
77
+ postcss-html
78
+ stylelint-config-prettier -D
79
+ - pnpm install stylelint stylelint-config-html stylelint-config-recommended-scss stylelint-config-recommended-vue stylelint-config-standard stylelint-config-standard-scss stylelint-config-recess-order postcss postcss-html stylelint-config-prettier -D
80
+ - ![](https://cdn.jsdelivr.net/gh/aafyfhh/imagebase/content/img/20260126142238769.png)
81
+ - 保存后就能发现 css 的顺序会变化,且不会报错
82
+
83
+ ## prettier 和 eslint 冲突
84
+
85
+ - 一些配置项冲突,需要自行处理。比如单引号双引号需要统一,
86
+ 不然会出现反复横跳的情况。
87
+ - 结尾分号逗号等,需要统一,不然会出现反复横跳的情况。
88
+
89
+ ## git工作流规范
90
+
91
+ - git工作流规范
92
+ 如何确保团队成员都遵循ESint规则,且不会将不符合规范的代码推送到Git仓库?
93
+ 答案是:使用带有git hooks功能的husky。git hooks是git内置的功能,它会在执行Git命令之前(或之后)进行一些其它操作。例如ESLint规则校验。husky依靠git hooks来触发EsLint规则校验,并确保团队成员提交和推送代码到git之前的代码无任何问题。
94
+ - githooks文件在.git目录下有示例文件
95
+ - husky 是什么
96
+ - 管理git hooks,因为 git hooks 不会被提交到 git 中,只会在本地生效。
97
+ - 所以我们需要在本地安装 husky 依赖,然后在 package.json 文件中添加 prepare 脚本,来在安装依赖后自动配置 git hooks。
98
+ - 安装依赖:pnpm install husky -D
99
+ - 添加 prepare 脚本:npm pkg set scripts.prepare="husky install"和 prepare: "husky install"命令是一个意思
100
+ - 运行脚本:pnpm run prepare,生成 husky 文件夹
101
+ - 会生成.husky/pre-commit文件和.husky/commit-msg文件,分别对应pre-commit和commit-msg钩子。
102
+ 还有其他钩子:
103
+ - pre-receive:从本地版本完成一个推送后
104
+ - prepare-commit-msg:信息准备完成后但编辑尚未启动
105
+ - pre-push:push 之前执行
106
+ - post-update:在工作区更新完成后执行
107
+ - pre-rebase:在rebase操作之前执行
108
+ - 添加pre-commit内容
109
+
110
+ ```
111
+ #!/usr/bin/env sh
112
+ . "$(dirname -- "$0")/_/husky.sh"
113
+ npx eslint src
114
+ ```
115
+
116
+ - 安装依赖:pnpm install lint-staged -D
117
+ - 只在我们更改的代码上运行 ESLint
118
+ - 添加脚本:"lint:lint-staged": "lint-staged"
119
+ - 新增lint-staged.config.cjs文件
120
+ - 完善 lint-staged.config.cjs 配置说明,解释每个设置项的作用和意义
121
+
122
+ ## git提交规范
123
+
124
+ - git 有两个常用的钩子:一个是 pre-commit,一个是 commit-msg
125
+ - 安装依赖: pnpm install @commitlint/cli @commitlint/config-conventional -D
126
+ - @commitlint/config-conventional 是基于 conventional commits 规范的配置文件。
127
+ - @commitlint/cli 是 commitlint 工具的核心。
128
+ - 安装husky:pnpm install husky -D
129
+ - 创建.husky/pre-commit文件和.husky/commit-msg文件
130
+ - 分别添加如下内容:
131
+ - pre-commit文件:
132
+ - npm run type-check
133
+ - commit-msg文件:
134
+ - npx --no-install commitlint --edit "$1"
135
+ - 添加 prepare 脚本
136
+ - "prepare": "husky install"
137
+ - 创建commitlint.config.cjs文件
138
+ - 完善 commitlint.config.cjs 配置说明,解释每个设置项的作用和意义
139
+ - build: 改变了项目构建系统或外部依赖项。
140
+ - ci: 更改了CI配置或脚本。
141
+ - docs: 只更改文档。
142
+ - feat: 新功能。
143
+ - fix: 修复了一个 bug。
144
+ - perf: 改进了性能。
145
+ - refactor: 代码重构,既没有增加新功能,也没有修复 bug。
146
+ - style: 格式化、缺少分号等;对代码逻辑没有影响的更改。
147
+ - test: 增加或修改了测试代码。
148
+ - 安装 pnpm add commitizen cz-conventional-changelog -D
149
+ - 这是为了不用自己输入描述,使用 cz-conventional-changelog 插件来生成描述。
150
+ - package.json配置
151
+
152
+ ```"scripts": {
153
+ //......其他省略
154
+ "commit": "git add -A && git-cz"
155
+ },
156
+ "config": {
157
+ "commitizen": {
158
+ "path": "./node_modules/cz-conventional-changelog"
159
+ }
160
+ }
161
+ ```
162
+
163
+ - 运行脚本:pnpm run commit
164
+ - 这会触发 git-cz 插件,生成符合 conventional commits 规范的提交信息。
165
+ - 按照提示输入信息,即可生成符合规范的提交信息。
166
+ - 不过这都是英文
167
+ - 使用 cz-git
168
+ - 安装依赖:pnpm install cz-git -D,前提是已经安装commitizen
169
+ - 配置 cz-git 插件:
170
+ - 在 package.json 文件中添加如下配置:
171
+
172
+ ```"scripts":{
173
+ "commit": "git add -A && git-cz"
174
+ }
175
+ "config": {
176
+ "commitizen": {
177
+ "path": "cz-git"
178
+ }
179
+ }
180
+ ```
181
+
182
+ - 配置模板
183
+ - <https://cz-git.qbb.sh/zh/config/>
184
+ ,我们在之前的commitlint.config.cjs文件上,进行修改
185
+ - 再次运行脚本:pnpm run commit,就能规范提交信息了
186
+ - 还可以使用 git-commit-plugin 插件来进行规范化提交,但是灵活性不足
@@ -0,0 +1,101 @@
1
+ /**
2
+ *
3
+ 继承了@commitlint/config-conventional 规则集,定义了Git 提交信息定义一致性格式
4
+ build: 改变了项目构建系统或外部依赖项。
5
+ ci: 更改了CI配置或脚本。
6
+ docs: 只更改文档。
7
+ feat: 新功能。
8
+ fix: 修复了一个 bug。
9
+ perf: 改进了性能。
10
+ refactor: 代码重构,既没有增加新功能,也没有修复 bug。
11
+ style: 格式化、缺少分号等;对代码逻辑没有影响的更改。
12
+ test: 增加或修改了测试代码。
13
+ */
14
+ // module.exports = { extends: ['@commitlint/config-conventional'] }
15
+
16
+ // @see: https://cz-git.qbenben.com/zh/guide
17
+ const fs = require('node:fs')
18
+ const path = require('node:path')
19
+
20
+ const scopes = fs
21
+ .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true })
22
+ .filter(dirent => dirent.isDirectory())
23
+ .map(dirent => dirent.name.replace(/s$/, ''))
24
+
25
+ /** @type {import('cz-git').UserConfig} */
26
+ module.exports = {
27
+ ignores: [commit => commit.includes('init')],
28
+ extends: ['@commitlint/config-conventional'],
29
+ rules: {
30
+ // @see: https://commitlint.js.org/#/reference-rules
31
+ 'body-leading-blank': [2, 'always'],
32
+ 'footer-leading-blank': [1, 'always'],
33
+ 'header-max-length': [2, 'always', 108],
34
+ 'subject-empty': [2, 'never'],
35
+ 'type-empty': [2, 'never'],
36
+ 'subject-case': [0],
37
+ 'type-enum': [
38
+ 2,
39
+ 'always',
40
+ [
41
+ 'feat',
42
+ 'fix',
43
+ 'docs',
44
+ 'style',
45
+ 'refactor',
46
+ 'perf',
47
+ 'test',
48
+ 'build',
49
+ 'ci',
50
+ 'chore',
51
+ 'revert',
52
+ 'wip',
53
+ 'workflow',
54
+ 'types',
55
+ 'release',
56
+ ],
57
+ ],
58
+ },
59
+ prompt: {
60
+ messages: {
61
+ // 中文版
62
+ type: '选择你要提交的类型 :',
63
+ scope: '选择一个提交范围(可选):',
64
+ customScope: '请输入自定义的提交范围 :',
65
+ subject: '填写简短精炼的变更描述 :\n',
66
+ body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
67
+ breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
68
+ footerPrefixsSelect: '选择关联issue前缀(可选):',
69
+ customFooterPrefixs: '输入自定义issue前缀 :',
70
+ footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
71
+ confirmCommit: '是否提交或修改commit?',
72
+ },
73
+ types: [
74
+ // 中文版
75
+ { value: 'feat', name: '特性: 🚀 新增功能', emoji: '🚀' },
76
+ { value: 'fix', name: '修复: 🧩 修复缺陷', emoji: '🧩' },
77
+ { value: 'docs', name: '文档: 📚 文档变更', emoji: '📚' },
78
+ { value: 'style', name: '格式: 🎨 代码格式(不影响功能,例如空格、分号等格式修正)', emoji: '🎨' },
79
+ { value: 'refactor', name: '重构: ♻️ 代码重构(不包括 bug 修复、功能新增)', emoji: '♻️' },
80
+ { value: 'perf', name: '性能: ⚡️ 性能优化', emoji: '⚡️' },
81
+ { value: 'test', name: '测试: ✅ 添加疏漏测试或已有测试改动', emoji: '✅' },
82
+ {
83
+ value: 'build',
84
+ name: '构建: 📦️ 构建流程、外部依赖变更(如升级 npm 包、修改 webpack 配置等)',
85
+ emoji: '📦️',
86
+ },
87
+ { value: 'ci', name: '集成: 🎡 修改 CI 配置、脚本', emoji: '🎡' },
88
+ { value: 'chore', name: '回退: ⏪️ 回滚 commit', emoji: '⏪️' },
89
+ { value: 'revert', name: '其他: 🔨 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)', emoji: '🔨' },
90
+ { value: 'wip', name: '开发: 🕔 正在开发中', emoji: '🕔' },
91
+ { value: 'workflow', name: '工作流: 📋 工作流程改进', emoji: '📋' },
92
+ { value: 'types', name: '类型: 🔰 类型定义文件修改', emoji: '🔰' },
93
+ ],
94
+ useEmoji: true,
95
+ scopes: [...scopes],
96
+ customScopesAlign: 'bottom',
97
+ emptyScopesAlias: 'empty',
98
+ customScopesAlias: 'custom',
99
+ allowBreakingChanges: ['feat', 'fix'],
100
+ },
101
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,31 @@
1
+ import antfu from '@antfu/eslint-config'
2
+ import eslintConfigPrettier from 'eslint-config-prettier'
3
+
4
+ export default antfu(
5
+ {
6
+ stylistic: false,
7
+
8
+ // TypeScript and Vue are autodetected, you can also explicitly enable them:
9
+ typescript: true,
10
+ vue: true,
11
+
12
+ // Disable jsonc and yaml support
13
+ jsonc: false,
14
+ yaml: false,
15
+
16
+ // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
17
+ ignores: [
18
+ '**/fixtures',
19
+ '**/dist',
20
+ '**/node_modules',
21
+ '**/public',
22
+ // ...globs
23
+ ],
24
+ },
25
+ {
26
+ rules: {
27
+ 'no-console': 'warn',
28
+ },
29
+ },
30
+ eslintConfigPrettier,
31
+ )
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <link rel="icon" href="/favicon.ico">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.ts"></script>
12
+ </body>
13
+ </html>