Vue源码学习——目录结构
- 目录结构:
-scripts:包含与构建相关的脚本和配置文件。
-dist:构建后文件的输出目录
-flow:包含Flow的类型声明。这些声明是全局加载的,将在普通源代码中看到它们在类型注释中使用。
-packages: 包含vue-server-renderer和vue-template-compiler,( 它们是从源代码自动生成的,并且始终与主vue包具有相同的版本。它们作为单独的NPM包分发。)
-test:包含所有测试。单元测试用Jasmine编写并与Karma一起运行。e2e测试是为Nightwatch.js编写并运行的。
-src:显然包含源代码。代码库是使用Flow类型注释在ES2015中编写的。
-----compiler
:
包含模板到渲染函数编译器的代码;
---------parser
(
将template转换成抽象语法树AST
)。
---------
optimizer (检测静态树以进行vdom渲染优化)
---------
codegen (直接从元素AST生成代码字符串, 它以较小的代码大小完成,因为编译器在独立构建中被运送到浏览器。)
-----core
:
包含通用的,与平台无关的运行时代码。
---------observer:反应系统,包含数据观测的核心代码
---------vdom:包含虚拟DOM创建(creation)和打补丁(patching)的代码
---------instance:包含Vue实例构造函数设计和原型函数相关的代码
---------global-api: 包含给Vue构造函数挂载全局方法(静态方法)或属性的代码
---------components: 抽象通用组件,目前只有keep-alive
-----server
:
服务端渲染相关代码
-----platforms
:
包含特定平台的代码;
build dist
的入口文件在各自平台的目录下。(
Each platform module contains three parts:
compiler
,
runtime
and
server
, corresponding to the three directories above. Each part contains platform-specific modules/utilities which are then imported and injected to the core counterparts in platform-specific entry files. For example, the code implementing the logic behind v-bind:class is in platforms/web/runtime/modules/class.js - which is imported in entries/web-runtime.js and used to create the browser-specific vdom patching function.
)
-----sfc
:
包含单文件组件
(.vue
文件
)
的解析逻辑,用于
vue-template-compiler
包
-----shared
:
包含整个代码库通用的代码
-----types
:
包含
TypeScript 类型定义
---------test:
类型定义测试