feat(react19-migration): 阶段1 - 项目基础设施重建

- T1.1: 卸载 Vue 依赖,安装 React 19 + Ant Design 5 + Zustand 5 + AntV 全家桶
- T1.2: Vite 配置迁移 (plugin-vue → plugin-react, manualChunks 更新)
- T1.3: TypeScript 配置迁移 (jsx: preserve → react-jsx, 移除 .vue)
- T1.4: ESLint 配置迁移 (Vue 规则 → React/Hooks/Refresh 规则)
- T1.5: 入口文件迁移 (main.ts → main.tsx, App.vue → App.tsx, div#app → div#root)

验证: npm run dev 成功启动空白 React 应用
This commit is contained in:
张翔
2026-05-03 15:14:24 +08:00
committed by zhangxiang
parent 7ba9d32a31
commit e4111ddb1a
16 changed files with 6973 additions and 1527 deletions
+15 -14
View File
@@ -1,25 +1,26 @@
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true
},
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:vue/vue3-recommended',
'plugin:@typescript-eslint/recommended'
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react/jsx-runtime',
],
parser: 'vue-eslint-parser',
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
parser: '@typescript-eslint/parser',
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: { jsx: true },
},
plugins: ['vue', '@typescript-eslint'],
plugins: ['react-refresh'],
rules: {
'vue/multi-word-component-names': 'off',
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react/prop-types': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }]
}
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
settings: { react: { version: 'detect' } },
}
+2 -2
View File
@@ -7,7 +7,7 @@
<title>Novalon 管理系统</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+6636 -1183
View File
File diff suppressed because it is too large Load Diff
+29 -18
View File
@@ -7,9 +7,9 @@
"dev": "vite",
"dev:local": "vite --mode development-local",
"dev:test": "vite --mode test",
"build": "vue-tsc && vite build",
"build:test": "vue-tsc && vite build --mode test",
"build:prod": "vue-tsc && vite build --mode production",
"build": "tsc --noEmit && vite build",
"build:test": "tsc --noEmit && vite build --mode test",
"build:prod": "tsc --noEmit && vite build --mode production",
"preview": "vite preview",
"test": "vitest --run",
"test:ui": "vitest --ui",
@@ -29,41 +29,52 @@
"test:parallel-opt": "playwright test parallel-optimization.spec.ts",
"test:all-opt": "playwright test edge-cases.spec.ts performance-optimization.spec.ts parallel-optimization.spec.ts",
"test:monitor": "node e2e/performanceMonitor.js report",
"type-check": "vue-tsc --noEmit",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx --fix --ignore-path .gitignore",
"type-check": "tsc --noEmit",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.2",
"axios": "^1.6.2",
"@ant-design/icons": "^6.2.2",
"@ant-design/pro-components": "^2.8.10",
"@antv/g2": "^5.4.8",
"@antv/g6": "^5.1.0",
"@antv/l7": "^2.25.4",
"@antv/l7-maps": "^2.25.4",
"@antv/s2": "^2.7.0",
"antd": "^5.29.3",
"axios": "^1.16.0",
"crypto-js": "^4.2.0",
"date-fns": "^4.1.0",
"dayjs": "^1.11.10",
"element-plus": "^2.13.5",
"jwt-decode": "^4.0.0",
"pinia": "^3.0.4",
"vue": "^3.5.26",
"vue-i18n": "^9.8.0",
"vue-router": "^4.6.4"
"react": "^19.2.5",
"react-dom": "^19.2.5",
"react-router": "^7.14.2",
"zustand": "^5.0.12"
},
"devDependencies": {
"@playwright/test": "^1.40.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^14.6.1",
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.10.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@vitejs/plugin-vue": "^6.0.3",
"@vitejs/plugin-react": "^5.2.0",
"@vitest/coverage-v8": "^4.1.1",
"@vitest/ui": "^4.0.16",
"@vue/test-utils": "^2.4.3",
"eslint": "^8.56.0",
"eslint-plugin-vue": "^9.19.2",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.4.26",
"jsdom": "^27.4.0",
"prettier": "^3.1.1",
"terser": "^5.46.1",
"typescript": "^5.9.3",
"vite": "^7.3.1",
"vitest": "^4.0.16",
"vue-tsc": "^3.2.2"
"vitest": "^4.0.16"
}
}
}
+15
View File
@@ -0,0 +1,15 @@
import { ConfigProvider } from 'antd'
import zhCN from 'antd/locale/zh_CN'
function App() {
return (
<ConfigProvider locale={zhCN}>
<div style={{ padding: 24 }}>
<h1>Novalon Manage System</h1>
<p>React 19 ...</p>
</div>
</ConfigProvider>
)
}
export default App
-6
View File
@@ -1,6 +0,0 @@
<template>
<router-view />
</template>
<script setup lang="ts">
</script>
@@ -1,43 +0,0 @@
<template>
<el-sub-menu
v-if="menu.children && menu.children.length > 0"
:index="String(menu.id)"
>
<template #title>
<el-icon v-if="menu.icon">
<component :is="iconComponents[menu.icon]" />
</el-icon>
<span>{{ menu.name }}</span>
</template>
<menu-item
v-for="child in menu.children"
:key="child.id"
:menu="child"
/>
</el-sub-menu>
<el-menu-item
v-else
:index="menu.path"
>
<el-icon v-if="menu.icon">
<component :is="iconComponents[menu.icon]" />
</el-icon>
<span>{{ menu.name }}</span>
</el-menu-item>
</template>
<script setup lang="ts">
import type { MenuItem as MenuItemType } from '@/stores/permission'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { markRaw, type Component } from 'vue'
const iconComponents: Record<string, Component> = {}
Object.keys(ElementPlusIconsVue).forEach(key => {
iconComponents[key] = markRaw(ElementPlusIconsVue[key as keyof typeof ElementPlusIconsVue])
})
defineProps<{
menu: MenuItemType
}>()
</script>
@@ -1,33 +0,0 @@
import type { Directive, DirectiveBinding } from 'vue'
import { usePermissionStore } from '@/stores/permission'
export const permissionDirective: Directive = {
mounted(el: HTMLElement, binding: DirectiveBinding) {
const permissionStore = usePermissionStore()
const { arg, value } = binding
const checkType = arg || 'permission'
if (!value) {
console.warn('v-permission 指令需要提供权限值')
el.style.display = 'none'
return
}
let hasAccess = false
if (checkType === 'role') {
hasAccess = permissionStore.hasRole(value)
} else if (checkType === 'permission') {
hasAccess = permissionStore.hasPermission(value)
} else {
console.warn(`未知的权限检查类型: ${checkType}`)
el.style.display = 'none'
return
}
if (!hasAccess) {
el.style.display = 'none'
}
}
}
@@ -1,166 +0,0 @@
<template>
<el-container class="default-layout">
<el-aside
:width="collapsed ? '64px' : '200px'"
class="aside"
>
<div class="logo">
<span v-if="!collapsed">Novalon</span>
<span v-else>N</span>
</div>
<el-menu
:default-active="activeMenu"
class="menu"
:collapse="collapsed"
background-color="#f5f7fa"
text-color="#606266"
active-text-color="#409eff"
router
>
<div v-if="menuTree.length === 0" style="padding: 20px; text-align: center; color: #999;">
菜单加载中...
</div>
<menu-item
v-for="menu in menuTree"
:key="menu.id"
:menu="menu"
/>
</el-menu>
</el-aside>
<el-container>
<el-header class="header">
<el-icon
class="trigger"
@click="collapsed = !collapsed"
>
<Fold v-if="!collapsed" />
<Expand v-else />
</el-icon>
<div class="header-right">
<el-dropdown @command="handleCommand">
<el-avatar :size="32">
{{ username }}
</el-avatar>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="profile">
个人中心
</el-dropdown-item>
<el-dropdown-item
command="logout"
divided
>
退出登录
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</el-header>
<el-main class="content">
<router-view />
</el-main>
</el-container>
</el-container>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Fold, Expand } from '@element-plus/icons-vue'
import { usePermissionStore } from '@/stores/permission'
import MenuItem from '@/components/MenuItem.vue'
const router = useRouter()
const route = useRoute()
const collapsed = ref(false)
const username = ref(localStorage.getItem('username') || 'Admin')
const permissionStore = usePermissionStore()
const activeMenu = computed(() => route.path)
const menuTree = computed(() => {
return permissionStore.menus
})
const handleCommand = (command: string) => {
if (command === 'profile') {
router.push('/profile')
} else if (command === 'logout') {
permissionStore.clearPermissionData()
localStorage.clear()
router.push('/login')
}
}
onMounted(async () => {
const token = localStorage.getItem('token')
if (!token) {
router.push('/login')
} else if (!permissionStore.loaded) {
permissionStore.initFromStorage()
if (!permissionStore.loaded || permissionStore.menus.length === 0) {
try {
await permissionStore.fetchUserMenus()
} catch (error) {
console.error('获取用户菜单失败:', error)
}
}
}
})
</script>
<style scoped lang="css">
.default-layout {
min-height: 100vh;
}
.aside {
background-color: #f5f7fa;
transition: width 0.3s;
overflow: hidden;
}
.logo {
height: 64px;
display: flex;
align-items: center;
justify-content: center;
color: #303133;
font-size: 20px;
font-weight: bold;
}
.menu {
border-right: none;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 16px;
background: #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
.trigger {
font-size: 18px;
cursor: pointer;
transition: color 0.3s;
&:hover { color: #409eff; }
}
.header-right {
display: flex;
align-items: center;
}
}
.content {
margin: 16px;
padding: 16px;
background: #fff;
min-height: calc(100vh - 96px);
}
</style>
-22
View File
@@ -1,22 +0,0 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import router from './router'
import App from './App.vue'
import './assets/styles.css'
import { permissionDirective } from './directives/permission'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(router)
app.use(ElementPlus, {
locale: zhCn,
})
app.directive('permission', permissionDirective)
app.mount('#app')
+10
View File
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './assets/styles.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
-9
View File
@@ -1,10 +1 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_SIGNATURE_SECRET: string
readonly VITE_API_BASE_URL?: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
+2 -9
View File
@@ -2,31 +2,24 @@
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"jsx": "react-jsx",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
/* Path mapping */
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx"],
"references": [{ "path": "./tsconfig.node.json" }]
}
+9 -22
View File
@@ -1,9 +1,9 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import react from '@vitejs/plugin-react'
import path from 'path'
export default defineConfig({
plugins: [vue()],
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
@@ -20,26 +20,22 @@ export default defineConfig({
secure: false
}
},
hmr: {
overlay: false
},
hmr: { overlay: false },
cors: true
},
build: {
target: 'esnext',
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
compress: { drop_console: true, drop_debugger: true }
},
rollupOptions: {
output: {
manualChunks: {
'vue-vendor': ['vue', 'vue-router', 'pinia'],
'element-plus': ['element-plus'],
'utils': ['axios']
'react-vendor': ['react', 'react-dom', 'react-router'],
'antd': ['antd'],
'antv': ['@antv/g2', '@antv/g6', '@antv/l7', '@antv/s2'],
'utils': ['axios', 'date-fns']
}
}
},
@@ -47,15 +43,6 @@ export default defineConfig({
reportCompressedSize: false
},
optimizeDeps: {
include: ['vue', 'vue-router', 'pinia', 'element-plus', 'axios'],
exclude: []
},
css: {
devSourcemap: false,
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/variables.scss";`
}
}
include: ['react', 'react-dom', 'react-router', 'zustand', 'antd', 'axios']
}
})