refactor: 升级开发依赖, 包含 Vite ESModule Prettier ESLint Typescript 等基础设施

This commit is contained in:
BaboonKing 2024-11-19 20:59:22 +08:00
parent 0ab1465391
commit d60063e15e
12 changed files with 1775 additions and 2075 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
end_of_line = true
trim_trailing_whitespace = true

View File

@ -1,11 +0,0 @@
node_modules/
public/
es/
lib/
dist/
package.json
src/assets/
plop-templates/
handlebars/
website/
build/

View File

@ -1,30 +0,0 @@
module.exports = {
root: true,
parser: 'vue-eslint-parser',
globals: {
postMessage: true
},
parserOptions: {
parser: '@typescript-eslint/parser',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
tsx: true
}
},
env: {
node: true,
// The Follow config only works with eslint-plugin-vue v8.0.0+
'vue/setup-compiler-macros': true
},
extends: ['plugin:vue/vue3-essential', 'eslint:recommended'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-unused-vars': 'off',
'vue/no-unused-vars': 'off',
'vue/multi-word-component-names': 'off',
'vue/valid-template-root': 'off',
'vue/no-mutating-props': 'off'
}
}

8
.prettierignore Normal file
View File

@ -0,0 +1,8 @@
auto-imports.d.ts
components.d.ts
pnpm-lock.yaml
dist
/node_modules/*
.workflow
src/packages/components/Charts/Maps/MapBase/mapGeojson/*.json
store-template

60
eslint.config.js Normal file
View File

@ -0,0 +1,60 @@
import pluginVue from 'eslint-plugin-vue'
import vueTsEslintConfig from '@vue/eslint-config-typescript'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
export default [
{
name: 'app/files-to-lint',
files: ['**/*.{ts,mts,tsx,vue}']
},
{
name: 'app/files-to-ignore',
ignores: [
'**/dist/**',
'**/dist-ssr/**',
'**/coverage/**',
'node_modules/',
'public/',
'es/',
'lib/',
'dist/',
'package.json',
'src/assets/',
'plop-templates/',
'handlebars/',
'website/',
'build/'
]
},
...pluginVue.configs['flat/essential'],
...vueTsEslintConfig(),
skipFormatting,
{
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-unused-vars': 'off',
'vue/no-unused-vars': 'off',
'vue/multi-word-component-names': 'off',
'vue/valid-template-root': 'off',
'vue/no-mutating-props': 'off',
// TODO: 下面的规则后续放开,然后自动修复
'no-var': 'off',
'prefer-const': 'off',
'vue/no-ref-as-operand': 'off',
'vue/block-lang': 'off',
'vue/no-dupe-keys': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-duplicate-enum-values': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/consistent-type-imports': 'error'
}
}
]

View File

@ -4,15 +4,19 @@
"engines": {
"node": ">=16.14 <18.0.0"
},
"type": "module",
"packageManager": "pnpm@8.15.9",
"scripts": {
"dev": "vite --host",
"build": "vue-tsc --noEmit && vite build",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"new": "plop --plopfile ./plop/plopfile.js",
"postinstall": "husky install",
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.vue src",
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx,.vue src --fix"
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write ."
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
@ -42,7 +46,7 @@
"pinia": "^2.0.13",
"screenfull": "^6.0.1",
"three": "^0.145.0",
"vue": "^3.2.31",
"vue": "3.5.13",
"vue-demi": "^0.13.1",
"vue-i18n": "9.2.2",
"vue-router": "4.0.12",
@ -53,38 +57,37 @@
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@types/node": "^16.11.26",
"@tsconfig/node22": "22.0.0",
"@types/node": "22.9.0",
"@types/three": "^0.144.0",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"@vicons/carbon": "^0.12.0",
"@vicons/ionicons5": "~0.11.0",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"@vue/compiler-sfc": "^3.2.31",
"@vitejs/plugin-vue": "5.2.0",
"@vitejs/plugin-vue-jsx": "4.1.0",
"@vue/eslint-config-prettier": "10.1.0",
"@vue/eslint-config-typescript": "14.1.3",
"@vue/tsconfig": "0.6.0",
"@vueuse/core": "^7.7.1",
"commitlint": "^17.0.2",
"default-passive-events": "^2.0.0",
"echarts": "^5.3.2",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.5.0",
"eslint": "9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-vue": "9.31.0",
"husky": "^8.0.1",
"lodash": "~4.17.21",
"mockjs": "^1.1.0",
"npm-run-all2": "7.0.1",
"plop": "^3.0.5",
"prettier": "^2.6.2",
"sass": "^1.49.11",
"sass-loader": "^12.6.0",
"typescript": "4.6.3",
"vite": "4.3.6",
"vite-plugin-compression": "^0.5.1",
"prettier": "3.3.3",
"sass-embedded": "1.81.0",
"typescript": "5.6.3",
"vite": "5.4.11",
"vite-plugin-compression2": "1.3.1",
"vite-plugin-importer": "^0.2.5",
"vite-plugin-mock": "^2.9.6",
"vite-plugin-mock": "3.0.2",
"vite-plugin-monaco-editor": "^1.1.0",
"vue-echarts": "^6.0.2",
"vue-tsc": "^0.28.10"
"vue-tsc": "2.1.10"
}
}

3585
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
module.exports = {
export default {
printWidth: 120,
tabWidth: 2,
useTabs: false,
singleQuote: true,
semi: false,
trailingComma: "none",
trailingComma: 'none',
bracketSpacing: true,
jsxSingleQuote: true,
jsxBracketSameLine: false,
arrowParens: "avoid"
}
arrowParens: 'avoid'
}

14
tsconfig.app.json Normal file
View File

@ -0,0 +1,14 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "types/**/*"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

View File

@ -1,25 +1,11 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"baseUrl": ".",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"lib": ["es6", "ESNext", "dom"],
"types": ["vite/client"],
"paths": {
"@/*": ["src/*"],
"/#/*": ["types/*"]
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
"noImplicitAny": true, //使any
// "strictNullChecks": true, //使null
"noImplicitThis": true //this
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "types/**/*"],
"exclude": ["node_modules", "dist", "**/*.js"]
{
"path": "./tsconfig.app.json"
}
]
}

13
tsconfig.node.json Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "@tsconfig/node22/tsconfig.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "nightwatch.conf.*", "playwright.config.*"],
"compilerOptions": {
"composite": true,
"noEmit": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}

View File

@ -2,33 +2,22 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
import viteCompression from 'vite-plugin-compression'
import { compression } from 'vite-plugin-compression2'
import { viteMockServe } from 'vite-plugin-mock'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import { fileURLToPath } from 'url'
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir)
}
export default defineConfig({
base: '/',
base: process.env.NODE_ENV === 'production' ? './' : '/',
// 路径重定向
resolve: {
alias: [
{
find: /\/#\//,
replacement: pathResolve('types')
},
{
find: '@',
replacement: pathResolve('src')
},
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
}
],
dedupe: ['vue']
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
// 全局 css 注册
css: {
@ -48,7 +37,9 @@ export default defineConfig({
}
}
}),
monacoEditorPlugin({
// monacoEditorPlugin Not is ES Module
// @ts-expect-error
monacoEditorPlugin.default({
languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
}),
viteMockServe({
@ -63,13 +54,7 @@ export default defineConfig({
watchFiles: true
}),
// 压缩
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz'
})
compression({})
],
build: {
target: 'es2015',