瞭解Vue的構建,能夠從package.json文件開始
sprits命令內關於構建的命令以下css
{ ... "build": "node scripts/build.js」, // web版本 // sever "build:ssr": "npm run build -- web-runtime-cjs,web-server-renderer」, // weex "build:weex": "npm run build -- weex」 … }
從命令看出:vue
build
方法 et builds = require('./config').getAllBuilds() if (process.argv[2]) { const filters = process.argv[2].split(',') builds = builds.filter(b => { return filters.some(f => b.output.file.indexOf(f) > -1 || b._name.indexOf(f) > -1) }) } else { //. 若是沒有參數就把weex給過濾掉 builds = builds.filter(b => { return b.output.file.indexOf('weex') === -1 }) } build(builds)
獲得的整個的構建流程是:node
./config
配置文件中的配置,再根據命令行中輸入的參數,exports.getAllBuilds = () => Object.keys(builds).map(genConfig)
// Object.keys(builds) 對象key的數組: 對應val的是不一樣版本的編譯配置
// genConfig 配置rollup構建的參數格式webpack
其中的別名配置暫不作分析,具體代碼在scripts/alias
中,web
補充: 在咱們經常使用的web版Vue中,又區分了兩種獨立構建和運行時構建
npm
二者直接的使用差異json
Runtime Only 運行時構建,不包含模板編譯器,藉助vue-loader將.vue
文件編譯成js
優勢: 代碼體積輕量
缺點: 運行時須要藉助vue-loader,把template模版編譯成render函數
new Vue({數組
render (h) { return h('div', this.hi) }
})weex
Runtime+Compiler 包含模板編譯器
優勢: 動態把模版編譯成render函數
缺點: 體積大,對性能有損耗框架
new Vue({ template: '<div>{{ hi }}</div>' })