一、前置知识小tips
- 一些node库
- webpack-chain:可以理解为通过api的方式配置webpack(www.npmjs.com/package/web...
- extract-css:抽取html中的css(www.npmjs.com/package/ext...)
- is-file-esm:是否是esm模块
- esm、umd、cmd、amd:esm(ECMA规范,import语法)、cmd(老node的require语法,现在也支持):www.cnblogs.com/h-c-g/p/153...
- npm命令怎么编写:juejin.cn/post/695602...
- 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
- path.resolve和path.join的区别:stackoverflow.com/questions/3...
二、vue-cli脚手架是如何读取vue.config.js的
- 下载下来vue-cli的代码:github.com/vuejs/vue-c...
- 找到cli-service里的bin文件夹下:vue-cli-service.js
- 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...