项目package.json,workspace字段指向packages,加上安装的提示yarn安装,推测出 Yarn Workspace特性
Yarn Workspaces
"you only need to run yarn install
once to install all of them in a single pass."
只需要yarn install
一次就能完成安装所有所需模块包
"Your dependencies can be linked together" => "via a symlink"
可以相互链接
"if the /workspace-a/package.json
name
field was "pkg-a"
, the alias will be the following: /node_modules/pkg-a -> /workspace-a
"
可以在本地package的 package.json
的 设置name
字段,这样可以替换别名
node 模块加载
node解析规则: 如果传给 require()
的模块标识符不是核心模块,并且不以 '/'
、'../'
或 './'
开头,则 Node.js 从当前模块的父目录开始,并添加 /node_modules
,并尝试加载该位置的模块。 Node.js 不会将 node_modules
附加到已经以 node_modules
结尾的路径。
如果在那里找不到它,则它移动到父目录,依此类推,直到到达文件系统的根目录。
例如,如果 '/home/ry/projects/foo.js'
处的文件调用 require('bar.js')
,
则 Node.js 将按以下顺序查找以下位置:
/home/ry/projects/node_modules/bar.js
/home/ry/node_modules/bar.js
/home/node_modules/bar.js
/node_modules/bar.js
node中的symlink只在fs.symlink提到,但是找不到相关支持与支持版本
在window中打开
vue-next\packages\compiler-core
文件夹与vue-next\node_modules\@vue\compiler-core\
它的文件路径显示是不同的,这让我觉得是不同的文件夹,因为这与window中的快捷方式不同。但是仔细比对里面的文件,但又一模一样,应该是同一个文件夹。
因此require解析就会查询父级node_modules
,然后symlink到本地文件
vue@next
$npm dist-tag ls vue
beta: 3.2.0-beta.8
csp: 1.0.28-csp
latest: 2.6.14
next: 3.2.23
如何发布@next
版本
npm version prerelease --preid=next
看一下npm官网上vue版本,next
被称为npm库的Tag(区别于git)
npm | 淘宝镜像 |
---|---|
react
npm | 淘宝镜像 |
---|---|
webpack
npm | 淘宝镜像 |
---|---|
rollup
npm | 淘宝镜像 |
---|---|
exports
官文 vue package.json 存在一个exports字段
"exports": {
".": {
"import": {
"node": "./index.mjs",
"default": "./dist/vue.runtime.esm-bundler.js"
},
"require": "./index.js"
},
"./server-renderer": {
"import": "./server-renderer/index.mjs",
"require": "./server-renderer/index.js"
},
"./compiler-sfc": {
"import": "./compiler-sfc/index.mjs",
"require": "./compiler-sfc/index.js"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
子路径导出
在exports设置要导出的子路径。
注意:设置了exports字段就不能引用真实的子路径了
条件导出
node支持CommonJS模块与ESM,所以也支持不同模块体系的导出
支持字段:
import
ESMrequire
CommonJSnode
所有node-addons
C++支持default
=>node