vue源码之路径别名的技巧转换
//以web/entry-runtime.js为例子,base就是web,然后到aliases里去找里面刚好有web,就取到这个路径,再和剩余的/entry-runtime.js拼接,最终经过Rollup的构建打包,最终在dist目录下生成vue.runtime.common.js const aliases = require(‘./alias‘) const resolve = p => { const base = p.split(‘/‘)[0] if (aliases[base]) { return path.resolve(aliases[base], p.slice(base.length + 1)) } else { return path.resolve(__dirname, ‘../‘, p) } } const builds = { // Runtime only (CommonJS)builds. Used by bundlers e.g. Webpack & Browserify ‘web-runtime-cjs-dev‘: { //entry表?构建的?? JS ?件地址 //dest 属性表?构建后的 JS ?件地址 //format 属性表?构建的格式 //cjs 表?构建出来的 ?件遵循 CommonJS 规范, // es 表?构建出来的?件遵循 ES Module 规范。 // umd 表?构建出来的? 件遵循 UMD 规范。 entry: resolve(‘web/entry-runtime.js‘), dest: resolve(‘dist/vue.runtime.common.dev.js‘), format: ‘cjs‘, env: ‘development‘, banner }, ... }
alias.js
const path = require(‘path‘) const resolve = p => path.resolve(__dirname, ‘../‘, p) //这是一个对象存放着这些核心路径 module.exports = { vue: resolve(‘src/platforms/web/entry-runtime-with-compiler‘), compiler: resolve(‘src/compiler‘), core: resolve(‘src/core‘), shared: resolve(‘src/shared‘), web: resolve(‘src/platforms/web‘), weex: resolve(‘src/platforms/weex‘), server: resolve(‘src/server‘), sfc: resolve(‘src/sfc‘) }
相关推荐
源码zanqunet 2020-10-28
anchongnanzi 2020-09-21
CRMCRMCRMDS 2020-08-12
Cricket 2020-07-27
yuzhu 2020-11-16
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
sjcheck 2020-11-03
怪我瞎 2020-10-28
gloria0 2020-10-26
王军强 2020-10-21
学习web前端 2020-09-28
QiaoranC 2020-09-25
安卓猴 2020-09-12
Macuroon 2020-09-11
kiven 2020-09-11
LittleCoder 2020-09-11
Cheetahcubs 2020-09-13
小焊猪web前端 2020-09-10