How ouyangsh/hello-unibest works
Project Type and Purpose
• Unibest is a front-end framework/template for building multi-platform UniApp applications using Vue3, TypeScript, Vite, UnoCSS, Pinia, and related libraries.
• It provides a CLI-driven build pipeline to target H5 (web), Weixin Mini Program, and native App (via HBuilderX), complete with conventions for routing, layouts, request interceptors, i18n, and more.
File-Structure Analysis
• Top-Level Configurations and Scripts
• package.json, pnpm-lock.yaml, tsconfig.json, vite.config.ts, manifest.config.ts, pages.config.ts, uno.config.ts
• env/ (.env files for dev/test/prod), shell/ (post-install and rename scripts), mock/ (mock servers)
• Source Code (src/)
• src/main.ts & App.vue – application entry point
• src/pages.json, src/pages/… – convention-based routing definitions & page components
• src/layouts/ – layout wrappers (default.vue, demo.vue)
• src/components/ – reusable Vue components (fly-login, fly-navbar, qiun-data-charts, etc.)
• src/uni_modules/ – embedded third-party UniApp modules (lime-echart, sp-editor)
• src/hooks/, src/interceptors/ – cross-cutting logic for requests, uploads, navigation
• src/service/ – typed API definitions & mock data
• src/store/ – Pinia stores (user, count, etc.)
• src/locale/, src/i18n.d.ts – internationalization resources
• src/static/, src/assets/ – static assets for H5 and app platforms
• src/style/, src/uni.scss – global styles and UnoCSS configuration
• Distribution & Documentation
• dist/build/ – compiled outputs for each platform
• docs/ – generated documentation and demos
README Insights
• Describes supported platforms (web/H5, mp-weixin, app), commands (pnpm dev:h5, build:h5, etc.), and core features (layout, routing, interceptors, i18n).
• Shows technology stack: UniApp + Vue3 + TS + Vite + UnoCSS + wot-ui + z-paging.
Key Components
a. Developer & CLI Tools
• pnpm / Node.js / Vite / UniApp CLI
b. Build Pipeline
• Vite (dev server & bundler) → UniApp Plugin → Platform Bundles (H5, mp-weixin, app)
c. Core Application Modules
• Entry Point (main.ts + App.vue)
• Router & Pages (pages.json → src/pages/)
• Layouts (src/layouts/)
• UI Components (src/components/)
• Third-Party Uni Modules (src/uni_modules/)
• State Management (Pinia stores)
• Internationalization (i18n, locale files)
• Services & HTTP Layer (src/service/, src/interceptors/, src/hooks/useRequest.ts)
• Stylings (UnoCSS config, global SCSS)
d. External Services & Dependencies
• Backend APIs (real or mock via mock/_mockProdServer.ts)
• Third-party libraries (wot-ui, z-paging, echarts/uCharts)
• App runtime (HBuilderX, mobile OS runtime)
Component Relationships & Data Flow
• Developer invokes CLI → Vite Dev/Build → UniApp plugin processes Vue/TS → Outputs platform-specific bundles under dist/
• At runtime (H5): Browser loads index.html → JS bundle initializes Vue app → Router resolves pages → Components fetch data via HTTP hook → Interceptors handle auth & responses → Pinia stores hold app state → i18n provides translations
• At runtime (MiniProgram/App): Similar flow but under Weixin/App runtime, using manifest.config.ts and pages.config.ts for platform conventions
Architectural Patterns & Principles
• Convention-over-Configuration for routing (pages.json)
• Modular, feature-based organization: pages/, components/, uni_modules/
• Cross-cutting concerns isolated in interceptors/ and hooks/
• State encapsulated in Pinia stores
• Build-time plugin architecture (Vite + UniApp)
• Separation between:
• Build System (CLI & Vite)
• Core App Modules (entry, router, pages, layouts, components)
• Cross-cutting Services (interceptors, hooks, services, store)
• Platform Outputs (H5 bundle, MiniProgram bundle, App bundle)
• Configuration files (vite.config.ts, manifest.config.ts, pages.config.ts, env/*.env) feeding into the build pipeline
• Mock server as an optional external service