refactor: 前端构建按需化与 Mock 懒加载
移除全量 Element Plus 与全局 VChart 注册,改为按需引入样式与组件内局部图表;Mock 适配器改为按 VITE_ENABLE_MOCK 环境变量懒加载,生产默认不拦截请求;ECharts 精简为看板所需图表,各视图与 stores 同步适配。
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
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'
|
||||
|
||||
// Font Awesome 图标
|
||||
import '@/assets/font-awesome/css/font-awesome.min.css'
|
||||
|
||||
// ECharts(按需引入)+ vue-echarts 组件
|
||||
import '@/plugins/echarts'
|
||||
import VChart from 'vue-echarts'
|
||||
// 这三个能力通过函数或指令使用,无法由模板组件扫描自动补充样式。
|
||||
import 'element-plus/es/components/message/style/css'
|
||||
import 'element-plus/es/components/message-box/style/css'
|
||||
import 'element-plus/es/components/loading/style/css'
|
||||
|
||||
import App from './App.vue'
|
||||
import service from '@/api/request'
|
||||
import router from './router'
|
||||
import './styles/index.scss'
|
||||
|
||||
@@ -19,7 +15,19 @@ const app = createApp(App)
|
||||
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
app.use(ElementPlus, { locale: zhCn })
|
||||
app.component('VChart', VChart)
|
||||
|
||||
app.mount('#app')
|
||||
async function bootstrap() {
|
||||
// 开发环境默认使用 Mock;生产环境只有显式开启时才加载整套 Mock 数据。
|
||||
// 这样真实部署不会被前端适配器截断请求,也不会把 Mock 数据打进首屏包。
|
||||
const shouldEnableMock = import.meta.env.VITE_ENABLE_MOCK === 'true'
|
||||
|| (import.meta.env.DEV && import.meta.env.VITE_ENABLE_MOCK !== 'false')
|
||||
|
||||
if (shouldEnableMock) {
|
||||
const { installMockAdapter } = await import('@/mock/adapter')
|
||||
installMockAdapter(service)
|
||||
}
|
||||
|
||||
app.mount('#app')
|
||||
}
|
||||
|
||||
void bootstrap()
|
||||
|
||||
Reference in New Issue
Block a user