之所以选择v2.6.11是因为当前项目(腾讯云医)使用uniapp框架(v2.0.1-32920211122003)进行微信小程序开发,uniapp框架提供的vue运行时就是基于v2.6.11进行改造的。
Flow 是 facebook 出品的 JavaScript 静态类型检查工具。Vue.js 的源码利用了 Flow 做了静态类型检查。

基于rollup
命令参考package.json,如 npm run dev
// package.json
{
"scripts": {
"dev": "rollup -w -c scripts/config.js --environment TARGET:web-full-dev",
//...
}
}rollup -c 后面跟配置文件的路径,通过后面—environment参数,scripts/config.js会返回rollup进行构建的配置信息,指定了entry、dist等等配置信息,从而进行源码构建。
// scripts/config.js
const builds = {
//...
// Runtime+compiler development build (Browser)
'web-full-dev': {
entry: resolve('web/entry-runtime-with-compiler.js'),
dest: resolve('dist/vue.js'),
format: 'umd',
env: 'development',
alias: { he: './entity-decoder' },
banner
},
}
module.exports = genConfig(process.env.TARGET)从config.js文件中看到提供了多种环境的配置,这里重点关注浏览器环境(browser)下的两个版本:Runtime Only VS Runtime + Compiler
我们在使用 Runtime Only 版本的 Vue.js 的时候,通常需要借助如 webpack 的 vue-loader 工具把 .vue 文件编译成 JavaScript,因为是在编译阶段做的,所以它只包含运行时的 Vue.js 代码,因此代码体积也会更轻量。
比如我们可以指定TARGET:web-runtime-dev,即走下面配置,构建产物中便不提供在运行阶段进行模板编译的能力。
// scripts/config.js
const builds = {
//...
// runtime-only build (Browser)
'web-runtime-dev': {
entry: resolve('web/entry-runtime.js'),
dest: resolve('dist/vue.runtime.js'),
format: 'umd',
env: 'development',
banner
},
}
module.exports = genConfig(process.env.TARGET)因为在 Vue.js 2.0 中,最终渲染都是通过 render 函数,如果写 template 属性,则需要编译成 render 函数,那么这个编译过程会发生运行时,所以需要带有编译器的版本。
注意:后面我们使用 Runtime + Compiler (npm run dev) 版本进行分析,构建入口web/entry-runtime-with-compiler.js → src/platforms/web/entry-runtime-with-compiler.js