How meituan-dianping/mpvue works
Project type and purpose
• This is an open-source front-end framework (“mpvue”) that ports Vue.js (2.x) to multiple mini-program platforms (WeChat, Baidu, Toutiao, Alipay).
• It provides a compiler + runtime core, plus platform-specific plugins and build tooling so that Vue single-file components and render functions output code that runs in each mini-program environment.
File structure
• Top-level directories:
• src/ – core compiler, runtime, platform adapters, server (SSR) code
• packages/ – published npm packages (mpvue core, template-compilers, server-renderer, weex framework)
• build/ – build scripts, release automation, CI hooks
• dist/ – compiled bundles for direct CDN/browser use
• examples/ – sample apps demonstrating features
• benchmarks/ – performance tests for big-table, SSR, SVG, etc.
• test/ – unit & e2e tests separated by feature/platform
• Key patterns:
• Monorepo style – multiple related packages under one repo
• Compiler+runtime separation – src/compiler vs src/core
• Platform adapters – src/platforms/{mp,web,weex}
• Server-side rendering – src/server
• Configuration files:
• .babelrc, .eslintrc, flowconfig, package.json
• build/config.js, build/build.js
• circle.yml for CI
Insights from the README
• States mpvue is “Vue in mini programs,” preserving runtime reactivity & component model.
• Highlights support for multiple mini-program platforms and integration with webpack, Vue CLI, Vuex.
• Mentions companion projects (mpvue-loader, mpvue-webpack-target).
Top-level components
a. Core compiler & runtime
• Compiler: template parser → AST → codegen → render functions
• Runtime: reactive system, virtual DOM, component lifecycle, global API
b. Platform adapters
• mp (mini-program): compiler plugin + runtime shim mapping VDOM → mini-program API
• web: standard DOM runtime + full compiler
• weex: weex-specific runtime + compiler modules
c. Server-Side Rendering
• bundle-renderer, optimizing-compiler, template-renderer
d. Published packages (npm)
• mpvue (entry point for mp)
• mpvue-template-compiler, vue-template-compiler, weex-template-compiler
• vue-server-renderer
• weex-vue-framework
e. Build & Tooling
• build scripts (build/, dist/)
• webpack loader target (mpvue-loader, mpvue-webpack-target)
• CLI integration (vue-cli plugin)
f. Tests & Examples
• test/ for unit/e2e, examples/ and benchmarks/
Relationships and interactions
• Developer writes .vue files + Vuex store
• webpack + mpvue-loader invokes template compiler → produces JS render functions + JSON/ WXML/ WXSS
• Code invokes mpvue runtime (core + platform-adapter)
• Runtime renders to platform API (mini-program lifecycle, setData calls)
• SSR path: server create-renderer uses optimizing-compiler + renderers to produce HTML/stream
• Packaging: build scripts roll up source into dist/*.js for direct browser use
Architectural patterns & design principles
• Layered architecture: core → platform plugins → entry packages
• Plugin/adapter pattern: each platform implements the same compiler/runtime interface
• Monorepo modularization: share code via src/shared, src/sfc, types, build common code once
• CI/CD integration: automated builds, tests per platform
Final advice
• Be detailed: break “src/platforms/mp” into compiler vs runtime sub-components
• Monorepo structure and how each sub-package is published and consumed