How vuejs/vue works
Purpose and lifecycle
This is the end-of-life Vue 2 source repository: an ES5-compatible, progressive UI framework. It produces browser runtime/compiler builds plus companion packages for Single File Component (SFC) compilation and server-side rendering (SSR). Primary public build entry points are web runtime variants under src/platforms/web/entry-runtime.ts, src/platforms/web/entry-runtime-with-compiler.ts, and src/platforms/web/entry-compiler.ts.
Build and published surfaces
The monorepo uses pnpm workspaces and custom build orchestration. scripts/config.js defines build targets and aliases; scripts/build.js generates distributable artifacts, including dist/vue.common.js and dist/vue.runtime.common.js. Published package boundaries include the core Vue package, SFC compiler at packages/compiler-sfc/src/index.ts, template compiler package at packages/template-compiler/index.js, and SSR package at packages/server-renderer/src/index.ts.
Instance and public API layer
src/core/index.ts assembles the framework constructor. Instance initialization, option merging, state, lifecycle, events, injection, and render behavior are layered in src/core/instance/init.ts, src/core/instance/state.ts, and src/core/instance/lifecycle.ts. Global extension points—components, directives, plugins, mixins, subclasses—are installed through src/core/global-api/index.ts and its adjacent modules. This boundary turns user component options into initialized component instances.
Reactivity and update scheduling
Vue 2’s observation system converts data and arrays into dependency-tracked state. src/core/observer/index.ts creates observers, src/core/observer/dep.ts manages subscriptions, and src/core/observer/watcher.ts evaluates render/user/computed watchers. Mutations enqueue batched work through src/core/observer/scheduler.ts; the next-tick machinery then coordinates asynchronous DOM updates. The optional Vue 3-compatible APIs and proxy-style reactivity live separately in src/v3/index.ts and src/v3/reactivity/reactive.ts.
Rendering, VNodes, and browser patching
Render functions create VNodes and components via src/core/vdom/create-element.ts and src/core/vdom/create-component.ts. The platform-neutral patch algorithm in src/core/vdom/patch.ts reconciles old and new trees. The web adapter supplies real DOM operations and browser modules—attributes, classes, events, DOM properties, styles, transitions—through src/platforms/web/runtime/patch.ts, src/platforms/web/runtime/node-ops.ts, and src/platforms/web/runtime/modules/index.ts. This is the key core-to-browser boundary.
Template and SFC compilation
At build time or runtime-with-compiler, templates flow through parsing, optimization, and JavaScript render-function generation: src/compiler/parser/index.ts, src/compiler/optimizer.ts, and src/compiler/codegen/index.ts. Web-specific directives and compiler modules extend those generic stages under src/platforms/web/compiler/index.ts. SFC compilation independently parses .vue blocks and compiles script, template, styles, scoped CSS, and CSS variables in packages/compiler-sfc/src/parse.ts, packages/compiler-sfc/src/compileScript.ts, and packages/compiler-sfc/src/compileTemplate.ts; loaders/bundlers consume this API externally.
Server rendering
SSR runs the same component/VNode model without browser DOM patching. packages/server-renderer/src/create-renderer.ts exposes render-to-string/stream behavior, while packages/server-renderer/src/render.ts traverses VNodes into HTML using SSR modules and directives. Bundle rendering isolates application bundles in packages/server-renderer/src/bundle-renderer/create-bundle-renderer.ts; template integration and client asset injection are handled by packages/server-renderer/src/template-renderer/index.ts. Webpack plugins at packages/server-renderer/src/webpack-plugin/client.ts and packages/server-renderer/src/webpack-plugin/server.ts generate manifests consumed at this SSR boundary.
Main entry points: build.js Artifact builder · core/index.ts Vue constructor · create-element.ts VNode creation · parser/index.ts Template compiler pipeline
Components 22
Build & packages
- Build targets & aliases
scripts/config.js - Artifact builder · Generates distributable Vue artifacts.
scripts/build.js - Browser/CommonJS dist · Includes full and runtime-only common builds.
dist/vue.common.js
Core runtime
- Vue constructor · Assembles the framework constructor and public instance API.
src/core/index.ts - Instance initialization · Initializes options, state, lifecycle, events, and rendering.
src/core/instance/init.ts - Global extension API · Installs components, directives, plugins, mixins, and subclasses.
src/core/global-api/index.ts - Observation & deps · Observes data and tracks dependency subscriptions.
src/core/observer/index.ts - Watchers & scheduler · Evaluates watchers and batches asynchronous updates.
src/core/observer/watcher.ts - VNode creation · Creates VNodes and component VNodes for renders.
src/core/vdom/create-element.ts - Platform-neutral patch · Reconciles old and new VNode trees.
src/core/vdom/patch.ts - Vue 3-compatible APIs · Separate proxy-style reactivity and compatibility APIs.
src/v3/index.ts
Web platform
- Web runtime entry · Runtime-only browser build entry.
src/platforms/web/entry-runtime.ts - Web compiler entry · Runtime-with-compiler browser build entry.
src/platforms/web/entry-runtime-with-compiler.ts - DOM patch adapter · Connects core patching to DOM operations and browser modules.
src/platforms/web/runtime/patch.ts
Compilation
- Template compiler pipeline · Parses, optimizes, and generates render functions.
src/compiler/parser/index.ts - Web compiler extensions · Adds web directives and compiler modules.
src/platforms/web/compiler/index.ts - SFC compiler package · Parses and compiles .vue script, template, styles, and scoped CSS.
packages/compiler-sfc/src/index.ts - Template compiler package
packages/template-compiler/index.js
Server rendering
- SSR renderer · Renders the shared component and VNode model to strings or streams.
packages/server-renderer/src/create-renderer.ts - VNode-to-HTML traversal · Traverses VNodes with SSR modules and directives.
packages/server-renderer/src/render.ts - SSR bundle renderer · Runs application bundles in an isolated rendering context.
packages/server-renderer/src/bundle-renderer/create-bundle-renderer.ts - SSR template integration · Injects rendered content and client assets into templates.
packages/server-renderer/src/template-renderer/index.ts
Connections 23
- Build targets & aliases → Artifact builder: defines targets
- Artifact builder → Browser/CommonJS dist: generates
- Web runtime entry → Vue constructor: loads
- Web compiler entry → Vue constructor: loads
- Web compiler entry → Template compiler pipeline: includes
- Vue constructor → Instance initialization: installs instance API
- Vue constructor → Global extension API: installs global API
- Instance initialization → Observation & deps: observes state
- Observation & deps → Watchers & scheduler: notifies dependencies
- Watchers & scheduler → VNode creation: drives re-render
- VNode creation → Platform-neutral patch: produces trees for
- Platform-neutral patch → DOM patch adapter: uses platform adapter
- Vue 3-compatible APIs → Observation & deps: separate from
- Template compiler pipeline → Web compiler extensions: extended by
- Web compiler extensions → VNode creation: generates render functions
- SFC compiler package → Template compiler pipeline: compiles SFC templates through
- Template compiler package → Template compiler pipeline: publishes
- SSR renderer → VNode-to-HTML traversal: delegates rendering
- VNode-to-HTML traversal → VNode creation: consumes shared VNodes
- SSR bundle renderer → SSR renderer: renders app bundles with
- SSR template integration → SSR bundle renderer: integrates rendered bundles
- Artifact builder → Web runtime entry: bundles
- Artifact builder → Web compiler entry: bundles