[TOC]
*****
## web-compiler web編譯
>[info] import
~~~
;(導入)擴展,基礎編譯,web指令,web基礎工具
import { extend } from 'shared/util'
import { compile as baseCompile } from 'compiler/index'
import directives from 'web/compiler/directives/index'
import { isReservedTag, isUnaryTag, mustUseProp, getTagNamespace } from 'web/util/index'
~~~
>[info] module
~~~
;分別存儲保留空白,非保留空白
const cache1 = Object.create(null)
const cache2 = Object.create(null)
;編譯配置項
const baseOptions = {
expectHTML: true,
directives,
isReservedTag,
isUnaryTag,
mustUseProp,
getTagNamespace
}
;web編譯入口
export function compile (template, options) {
options = options
? extend(extend({}, baseOptions), options)
: baseOptions
return baseCompile(template, options)
}
;編譯成渲染函數
export function compileToFunctions (template, options = {}) {
;是否保留空白節點
options.preserveWhitespace = options.preserveWhitespace !== false
const cache = options.preserveWhitespace ? cache1 : cache2
;緩存檢查
if (cache[template]) {
return cache[template]
}
;準備編譯
const res = {}
const compiled = compile(template, options)
;渲染函數獲取
res.render = new Function(compiled.render)
;靜態渲染函數
const l = compiled.staticRenderFns.length
if (l) {
res.staticRenderFns = new Array(l)
for (let i = 0; i < l; i++) {
res.staticRenderFns[i] = new Function(compiled.staticRenderFns[i])
}
}
;緩存編譯結果
return (cache[template] = res)
}
~~~
>[info] export
- 概述
- 框架結構
- 編譯入口(\entries)
- web-compiler.js(web編譯)
- web-runtime.js(web運行時)
- web-runtime-wih-compiler.js(web編譯運行)
- web-server-renderer.js(web服務器渲染)
- 核心實現 (\core)
- index.js(核心入口)
- config.js(核心配置)
- core\util(核心工具)
- core\observer(雙向綁定)
- core\vdom(虛擬DOM)
- core\global-api(核心api)
- core\instance(核心實例)
- 模板編譯(\compiler)
- compiler\parser(模板解析)
- events.js(事件解析)
- helper.js(解析助手)
- directives\ref.js(ref指令)
- optimizer.js(解析優化)
- codegen.js(渲染生成)
- index.js(模板編譯入口)
- web渲染(\platforms\web)
- compiler(web編譯目錄)
- runtime(web運行時目錄)
- server(web服務器目錄)
- util(web工具目錄)
- 服務器渲染(\server)
- render-stream.js(流式渲染)
- render.js(服務器渲染函數)
- create-renderer.js(創建渲染接口)
- 框架流程
- Vue初始化
- Vue視圖數據綁定
- Vue數據變化刷新
- Vue視圖操作刷新
- 框架工具
- 基礎工具(\shared)
- 模板編譯助手
- 核心實例工具
- Web渲染工具
- 基礎原理
- dom
- string
- array
- function
- object
- es6
- 模塊(Module)
- 類(Class)
- 函數(箭頭)
- 字符串(擴展)
- 代理接口(Proxy)
- 數據綁定基礎
- 數據綁定實現
- mvvm簡單實現
- mvvm簡單使用
- vdom算法
- vdom實現
- vue源碼分析資料