Skip to main content

门户协议

portal: 协议类似于 link: 协议(它必须是文件夹的相对路径,无需复制即可使用),但目标被假定为

¥The portal: protocol is similar to the link: protocol (it must be a relative path to a folder which will be made available without copies), but the target is assumed to be a package instead.

yarn add react-dom@portal:./my-react-dom

¥Portals vs links

链接必须在假设其目标文件夹可能在安装完成之前不存在的情况下运行;这会阻止他们读取文件夹的内容(包括任何 package.json 文件),进而阻止他们列出依赖。

¥Links have to operate under the assumption that their target folder may not exist until the install is finished; this prevents them from reading the content of the folder, including any package.json files, and in turn preventing them from listing dependencies.

另一方面,门户必须在解析时存在,否则会抛出错误。这让它们可以读取 package.json 文件的内容,并像依赖树中的任何其他包一样进行处理 - 除了它的内容将直接提供给用户,而不是复制 就像 file: 会做的那样

¥Portals, on the other hand, must exist at resolution time or an error is thrown. This lets them read the content of the package.json file and be treated like any other package in the dependency tree - except that its content will be made directly available to the user, rather than copied like file: would do.