1. 程式人生 > >Vue原始碼學習(1)——目錄結構

Vue原始碼學習(1)——目錄結構

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: 型別定義測試