Introduction to Vue 3 Source Code and Debugging Setup
🎯 Introduction
Welcome to the first article in the Vue 3 source code course. Rather than covering API usage, we will open the implementation and explore what happens behind the reactive, ref, and watchEffect calls you use every day. We will explain unfamiliar concepts in plain language, one at a time.
By the end, you will be able to set up a local environment, set breakpoints in the browser, step through the source, and navigate the vuejs/core repository to find the code relevant to your questions.
🧱 Why Read Vue 3 Source Code?
Reading source takes time. Is it worth it? For everyday development, the benefits fall into three areas.
Troubleshoot with a clearer direction. Perhaps changing an object property failed to update the view, or a watch callback ran an unexpected extra time. API knowledge alone can leave you guessing. Understanding reactivity gives you a mechanism to investigate rather than relying on trial and error.
Make better coding decisions. Once you understand that updates are batched before rendering, you can explain why several consecutive assignments produce only one UI update. These choices follow from understanding the implementation rather than memorizing rules.
Understand API design decisions. Some Vue 3 designs, such as requiring .value on a ref, can initially feel awkward. Reading the source reveals the specific problems they solve. That understanding also helps when learning other frameworks.
✨ Version Notes
Before starting, let's establish the version and repository. This course uses Vue 3.5.x, with Node.js v22 + pnpm for debugging.
Vue 3 lives in the vuejs/core GitHub repository. It contains multiple packages rather than a single application. This organization is called a monorepo: reactivity, rendering, compilation, and other features each have their own package, managed together with pnpm.
This separation makes source reading easier. For reactivity, open reactivity directly instead of searching across directories as in Vue 2. If you have completed the Vue 2 source code course, you will recognize the same core ideas—reactivity, virtual DOM, and template compilation. This course emphasizes what changed in Vue 3.
🧭 A Map of the Source
With the version established, where should you look? The packages directory groups code by responsibility. The tree below highlights key files. Select a file to see its role; later articles explore these areas in detail:
Here is a quick reference to each package:
| Directory | Responsibility |
|---|---|
packages/vue | Combines the runtime and compiler into the browser-facing Vue build |
packages/runtime-dom | DOM operations, event handling, and the browser version of createApp |
packages/runtime-core | Platform-independent component instances, virtual DOM, and scheduling |
packages/reactivity | The reactivity system: reactive, ref, effect, and computed |
packages/compiler-core | Parses templates into an AST and generates render function code |
packages/compiler-dom | Adds DOM-specific compilation to compiler-core |
packages/shared | Shared utilities such as type checks and string processing |
runtime-core and reactivity are the main focus of this course: the former handles components and rendering, and the latter implements reactivity. Knowing the other packages' responsibilities is sufficient for now. The overall flow is: the compiler turns your template into a render function; runtime-core executes it to render the page; and reactivity requests another render when data changes. Each subsequent article explores part of this flow.
🛠 Setting Up a Debugging Environment
Let's make this practical: how do you run the source locally and set breakpoints? Setup takes only a few minutes, after which you can verify the explanations in the actual implementation.
This course was verified with Node.js v22 + pnpm. Clone the source and check out v3.5.13:
# Clone the repository (using Node.js v22 locally)
git clone https://github.com/vuejs/core.git vue3-source
cd vue3-source
# Check out v3.5.13 to match the course
git checkout v3.5.13
# Install dependencies (use pnpm for this monorepo; versions follow pnpm-lock.yaml)
pnpm install
workspace: protocol, which resolves dependencies within the repository. Installing with npm will not recognize these references in this setup.--legacy-peer-deps. Use options supported by your package manager; this does not change the subsequent debugging process.After installation, build a development version with source maps:
# Build development vue.js with warnings and source maps for debugging
pnpm run dev
A source map connects bundled code to its original source. A build combines many files, changing code locations. The browser uses the source map as a lookup table so breakpoints and stepping show the original files instead of only the bundle.
The output is packages/vue/dist/vue.global.js. Create a debugging page under packages/vue/examples, for example packages/vue/examples/debug/01-hello.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Debugging Vue 3 Source Code</title>
</head>
<body>
<div id="app"></div>
<script src="../../dist/vue.global.js"></script>
<script>
const { createApp, ref } = Vue;
const app = createApp({
setup() {
const count = ref(0);
// Change the data after two seconds to inspect the update flow
setTimeout(() => {
// The JavaScript debugger statement pauses execution when DevTools is open
debugger;
count.value++;
}, 2000);
return { count };
},
template: `<div>count: {{ count }}</div>`,
});
app.mount('#app');
</script>
</body>
</html>
<script setup>? It requires compilation by a build tool. This plain HTML debugging page has no such step, so writing setup() directly also makes the runtime processing easier to follow.Open the HTML file in a browser and open DevTools (F12). Execution will pause at debugger. Then:
- Find
packages/reactivity/src/ref.tsin the Sources panel; the source map connects the build output to this file. - Set breakpoints in relevant code such as
ReactiveEffectandtriggerRefValueby clicking a line number. - Step through execution to follow the calls triggered by changing
count.value.
This is the basic source-reading workflow: find the key function → set a breakpoint → inspect values and the call stack while stepping.
pnpm run dev produces a development build with source maps for debugging. The production build (pnpm run build) minifies code and removes warnings, making it less suitable for learning from the source.💡 Tips for Reading the Source
With the environment ready, how do you avoid getting lost? These habits help keep your exploration focused.
- Start with a specific question. Do not read every file from the first line. Ask, for example, how changing a ref's
.valueupdates the view, then follow the corresponding call chain. - Follow the entry point inward. Find
createAppinpackages/runtime-dom/src/index.ts, then follow mounting and rendering step by step. This is more effective than browsing files without a direction. - Verify your understanding with a small implementation. After studying a mechanism, write a simplified version in a few dozen lines, such as a mini reactivity system. Getting it working tests your understanding. Several articles include these exercises.
- Skip TypeScript types and peripheral branches initially. Vue 3 uses TypeScript to annotate variables and functions. You can skip those annotations while following the main logic. The excerpts in this course also omit types and nonessential branches for teaching.
🗺 Course Roadmap
Now that the environment and reading approach are ready, here is the full route. These eight articles cover reactivity, the runtime, and finally compilation:
- Introduction and setup (this article): repository layout and debugging tools.
- createApp and mounting: what happens between creating an application and rendering its component on the page.
- Proxy-based reactivity: how
reactiveintercepts reads and writes. - effect, dependency tracking, and triggering: how Vue records consumers and notifies them when data changes.
- ref and computed: intercepting
.valueand evaluating computed values lazily. - The scheduler and nextTick: batching updates and queuing asynchronous work.
- Virtual DOM and patching: updating only the parts of the page that change.
- Template compilation: template → AST → render function.
<script setup>, and reactivity APIs. If needed, complete the Vue 3 course first. The Vue 2 source code course is also helpful for comparing the two implementations.❓ Questions and Answers
Q1: Why split Vue 3 into multiple packages?
Packages give each module a clear responsibility and boundary. For example, the standalone reactivity package lets you focus on the reactive system without also reading unrelated implementation details.
Q2: Can I follow the course without knowing breakpoint debugging?
Yes, but spend a few minutes learning the Chrome DevTools Sources panel, breakpoints, and stepping. These are basic source-reading tools that we will use frequently.
Q3: How do pnpm run dev and pnpm run build differ?
pnpm run dev produces an unminified build with source maps and full warnings, suitable for debugging and learning. pnpm run build produces minified production output with warnings removed, which is harder to study.
Q4: Are the excerpts identical to the repository source?
They are simplified for teaching. TypeScript annotations and some peripheral branches are omitted while preserving the core logic. Each excerpt identifies its source file so you can compare it with the original.
Q5: Does this repeat the Vue 2 source code course?
The core ideas—reactivity, virtual DOM, and template compilation—are shared, but the implementations differ significantly. This course focuses on those differences and briefly reviews shared concepts.
🧪 Exercise
After setting up the environment, add a message ref to packages/vue/examples/debug/01-hello.html and display it on the page. Use browser breakpoints to observe the call chain when its .value changes.
const { createApp, ref } = Vue;
const app = createApp({
setup() {
const count = ref(0);
// Your code here: declare a ref named message
setTimeout(() => {
debugger;
// Your code here: change message's value
}, 2000);
return { count };
},
// Your code here: display message in the template too
template: `<div>count: {{ count }}</div>`,
});
Find packages/reactivity/src/ref.ts in Sources, set a breakpoint at triggerRefValue, and inspect the calls triggered by one change.
🎉 Your Vue 3 source debugging environment is ready, and you have a map of the course! Next, we will start at createApp and follow application creation through mounting.
