vue-cli脚手架是如何读取vue.config.js的

一、前置知识小tips

  1. 一些node库
  1. esm、umd、cmd、amd:esm(ECMA规范,import语法)、cmd(老node的require语法,现在也支持):www.cnblogs.com/h-c-g/p/153...
  2. npm命令怎么编写:juejin.cn/post/695602...
  3. process.pwd与__dirname的区别:

process.cwd() returns the current working directory,

i.e. the directory from which you invoked the node command.

__dirname returns the directory name of the directory containing the JavaScript source code file

  1. path.resolve和path.join的区别:stackoverflow.com/questions/3...

二、vue-cli脚手架是如何读取vue.config.js的

  1. 下载下来vue-cli的代码:github.com/vuejs/vue-c...
  2. 找到cli-service里的bin文件夹下:vue-cli-service.js
  3. cli-service文件夹里搜vue.config.js,找到了:

4.继续搜loadFileConfig顺藤摸瓜得出调用栈: Service.js里service在init里面调用loadUserOptions,loadUserOptions里调用loadFileConfig,就把用户的vue.config.js读入了

三、扩展阅读及自我练习

vite是如何读取vite.config.js的和vue.config.js的读取有什么不同? segmentfault.com/a/119000004...

相关推荐
睡觉zzz21 分钟前
vue3中的组件通信
vue.js
褪色的笔记簿24 分钟前
Vue 2 中动态新增属性丢失响应性原因探究
vue.js
褪色的笔记簿26 分钟前
探索 Vue.js 中 El-Form 的 resetFields 方法重置数据
vue.js
Cutey9162 小时前
前端如何实现菜单的权限控制(RBAC)
前端·javascript·设计模式
Jazzing2 小时前
Vue 3 Diff 算法中的 newIndexToOldIndexMap 详解
vue.js
cmoaciopm2 小时前
在MacOS 10.15上安装Node.js
macos·node.js
Jazzing2 小时前
Vue 3 Diff 算法中的 getSequence 源码解析
vue.js
miffycat2 小时前
Element UI ColorPicker 实时更新绑定值并转换 Hex 颜色的完整方案
vue.js
Three~stone3 小时前
Vue学习笔记集--scoped组件
vue.js·笔记·学习