项目搭建
node版本:20.11.1
pnpm版本:9.0.4
初始化
vue3最新的脚手架
pnpm create vite byelide-demo --template vue-ts
pnpm i
pnpm dev
改端口号:
vite.config.ts:
import {
defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
server:{
port: 8888
}
})
eslint+版本约束
版本约束
package.json
{
"name": "byelide-demo",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"lint":"eslint --fix .",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "3.4.26"
},
"devDependencies": {
"@vitejs/plugin-vue": "5.0.4",
"typescript": "5.4.5",
"vite": "5.2.10",
"vue-tsc": "2.0.15",
"eslint": "9.1.1"
}
}
pnpm lint
eslint配置
package.json加:
"eslint-plugin-vue":"9.25.0",
"vue-eslint-parser":"9.4.2"
eslint.config.js:
import pluginVue from 'eslint-plugin-vue';
import vueEslintParser from 'vue-eslint-parser'
export default [
{
files:["**/*,.{ts,tsx,vue}"],
rules: {
semi: "error",
"prefer-const": "error",
"no-console":'error'
}
}
];
再执行:
pnpm i
最终版本:
eslint.config.js:
import js from "@eslint/js";
import pluginVue from 'eslint-plugin-vue';
// importSort插件功能是:项目中引入插件的顺序必须先是官方,后是自己的插件
import importSort from 'eslint-plugin-simple-import-sort';
import vueEslintParser from 'vue-eslint-parser'
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
export default [
{
languageOptions:{
globals:{
...globals.browser,
computed:"readonly",
defineEmits:"readonly",
defineExpose:"readonly",
defineProps:"readonly",
onMounted:"readonly",
onUnmounted:"readonly",
reactive:"readonly",
ref:"readonly",
shallowReactive:"readonly",
shallowRef:"readonly",
toRef:"readonly",
toRefs:"readonly",
watch:"readonly",
watchEffect:"readonly"
}
}
},
{
files:["**/*,.{ts,tsx,vue}"],
ignores:[],
rules: {
...js.configs.recommended.rules,
...pluginVue.configs['flat/recommended'].rules,
"no-console":'error',
'no-debugger':"error",
"vue/valid-define-emits":"error",
"simple-import-sort/imports":"error"