API conventions:
# 前置知识
OOP面向对象编程
工厂函数、原型对象的方式。静态属性和方法、原型属性和方法。
原型链接 prototype chain
hasOwnProperty、defineProperty、instanceof
valeu && value.hasOwnProperty('__ob__') && value.__ob__ instanceof Observer
# 目录结构
接触任何一种框架,首先需要对 目标结构 (opens new window) 进行了解对源码有个大概印象!
src
├── api/ # api
│ ├── child.js
│ ├── data.js
│ ├── dom.js
│ ├── events.js
│ ├── global.js
│ └── lifecycle.js
├── compiler/ # 编译器
│ ├── compile.js
│ └── transclude.js
├── directives # 指令
│ ├── model
│ │ ├── checkbox.js
│ │ ├── default.js
│ │ ├── index.js
│ │ ├── radio.js
│ │ └── select.js
│ ├── attr.js
│ ├── class.js
│ ├── cloak.js
│ ├── component.js
│ ├── el.js
│ ├── events.js
│ ├── html.js
│ ├── if.js
│ ├── index.js
│ ├── on.js
│ ├── partial.js
│ ├── ref.js
│ ├── repeat.js
│ ├── show.js
│ ├── style.js
│ ├── text.js
│ ├── transition.js
│ └── with.js
├── filters # 过滤器
│ ├── array-filters.js
│ └── index.js
├── instance # 实例
│ ├── compile.js
│ ├── events.js
│ ├── init.js
│ └── scope.js
├── observer # 响应式
│ ├── array.js
│ ├── dep.js
│ ├── index.js
│ └── object.js
├── parsers # 解析
│ ├── directive.js
│ ├── expression.js
│ ├── path.js
│ ├── template.js
│ └── text.js
├── transition # 过渡
│ ├── css.js
│ ├── index.js
│ └── js.js
├── util # 工具方法
│ ├── debug.js
│ ├── dom.js
│ ├── env.js
│ ├── filter.js
│ ├── index.js
│ ├── lang.js
│ └── merge-option.js
├── batcher.js
├── cache.js # 配置
├── directive.js
├── vue.js # 入口文件
└── watcher.js
# Vue.js Contributing Guide
Hi! I'm really excited that you are interested in contributing to Vue.js. Before submitting your contribution, please make sure to take a moment and read through the following guidelines:
- Code of Conduct (opens new window)
- Issue Reporting Guidelines
- Pull Request Guidelines
- Development Setup
- Project Structure
# Issue Reporting Guidelines
- Always use https://new-issue.vuejs.org/ (opens new window) to create new issues.
# Pull Request Guidelines
The
master
branch is just a snapshot of the latest stable release. All development should be done in dedicated branches. Do not submit PRs against themaster
branch.Checkout a topic branch from the relevant branch, e.g.
dev
, and merge back against that branch.Work in the
src
folder and DO NOT checkindist
in the commits.It's OK to have multiple small commits as you work on the PR - GitHub will automatically squash it before merging.
Make sure
npm test
passes. (see development setup)If adding a new feature:
- Add accompanying test case.
- Provide a convincing reason to add this feature. Ideally, you should open a suggestion issue first and have it approved before working on it.
If fixing bug:
- If you are resolving a special issue, add
(fix #xxxx[,#xxxx])
(#xxxx is the issue id) in your PR title for a better release log, e.g.update entities encoding/decoding (fix #3899)
. - Provide a detailed description of the bug in the PR. Live demo preferred.
- Add appropriate test coverage if applicable.
- If you are resolving a special issue, add
# Development Setup
You will need Node.js (opens new window) version 8+, Java Runtime Environment (opens new window) (for running Selenium server during e2e tests) and yarn (opens new window).
After cloning the repo, run:
$ yarn # install the dependencies of the project
# Committing Changes
Commit messages should follow the commit message convention so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. If you are not familiar with the commit message convention, you can use npm run commit
instead of git commit
, which provides an interactive CLI for generating proper commit messages.
# Commonly used NPM scripts
# watch and auto re-build dist/vue.js
$ npm run dev
# watch and auto re-run unit tests in Chrome
$ npm run dev:test
# build all dist files, including npm packages
$ npm run build
# run the full test suite, including linting/type checking
$ npm test
There are some other scripts available in the scripts
section of the package.json
file.
The default test script will do the following: lint with ESLint -> type check with Flow -> unit tests with coverage -> e2e tests. Please make sure to have this pass successfully before submitting a PR. Although the same tests will be run against your PR on the CI server, it is better to have it working locally.
# Project Structure
scripts
: contains build-related scripts and configuration files. Usually, you don't need to touch them. However, it would be helpful to familiarize yourself with the following files:scripts/alias.js
: module import aliases used across all source code and tests.scripts/config.js
: contains the build configurations for all files found indist/
. Check this file if you want to find out the entry source file for a dist file.
dist
: contains built files for distribution. Note this directory is only updated when a release happens; they do not reflect the latest changes in development branches.See dist/README.md (opens new window) for more details on dist files.
flow
: contains type declarations for Flow (opens new window). These declarations are loaded globally and you will see them used in type annotations in normal source code.packages
: containsvue-server-renderer
andvue-template-compiler
, which are distributed as separate NPM packages. They are automatically generated from the source code and always have the same version with the mainvue
package.test
: contains all tests. The unit tests are written with Jasmine (opens new window) and run with Karma (opens new window). The e2e tests are written for and run with Nightwatch.js (opens new window).src
: contains the source code. The codebase is written in ES2015 with Flow (opens new window) type annotations.compiler
: contains code for the template-to-render-function compiler.The compiler consists of a parser (converts template strings to element ASTs), an optimizer (detects static trees for vdom render optimization), and a code generator (generate render function code from element ASTs). Note that codegen directly generates code strings from the element AST - it's done this way for smaller code size because the compiler is shipped to the browser in the standalone build.
core
: contains universal, platform-agnostic runtime code.The Vue 2.0 core is platform-agnostic. That is, the code inside
core
is able to be run in any JavaScript environment, be it the browser, Node.js, or an embedded JavaScript runtime in native applications.observer
: contains code related to the reactivity system.vdom
: contains code related to vdom element creation and patching.instance
: contains Vue instance constructor and prototype methods.global-api
: contains Vue global api.components
: contains universal abstract components.
server
: contains code related to server-side rendering.platforms
: contains platform-specific code.Entry files for dist builds are located in their respective platform directory.
Each platform module contains three parts:
compiler
,runtime
andserver
, corresponding to the three directories above. Each part contains platform-specific modules/utilities which are imported and injected to the core counterparts in platform-specific entry files. For example, the code implementing the logic behindv-bind:class
is inplatforms/web/runtime/modules/class.js
- which is imported inentries/web-runtime.js
and used to create the browser-specific vdom patching function.sfc
: contains single-file component (*.vue
files) parsing logic. This is used in thevue-template-compiler
package.shared
: contains utilities shared across the entire codebase.types
: contains TypeScript type definitionstest
: contains type definitions tests
# Financial Contribution
As a pure community-driven project without major corporate backing, we also welcome financial contributions via GitHub Sponsors and OpenCollective. Please consult the Sponsor Page (opens new window) for more details.
# Credits
Thank you to all the people who have already contributed to Vue.js!