简体   繁体   English

基于 NX 包的回购协议:projectRoot 与 workspaceRoot?

[英]NX package-based repo: projectRoot vs workspaceRoot?

If I have a package-based monorepo with NX, which directory is projectRoot , and which one is workspaceRoot ?如果我有一个带有 NX 的基于包的 monorepo,哪个目录是projectRoot ,哪个是workspaceRoot

From the docs ( https://nx.dev/reference/project-configuration ):从文档( https://nx.dev/reference/project-configuration ):

{projectRoot} and {workspaceRoot} {projectRoot} 和 {workspaceRoot}

{projectRoot} is a key word that is replaced by the path to the current project's root directory. {projectRoot} 是一个关键字,由当前项目根目录的路径替换。 {workspaceRoot} is a key word that is replaced by the path to the workspace root directory. {workspaceRoot} 是一个关键字,由工作区根目录的路径替换。

This is hilariously obvious and unhelpful explanation.这是非常明显和无益的解释。 I want to know which one is which, given I have this directory structure:我想知道哪个是哪个,因为我有这个目录结构:

(git repo root dir)
|
+- nx.json
+- package.json - it says `"workspaces": [ "packages/*" ]`
|
+- packages/
   |
   +- package1/
   +- package2/

Because package.json mentions my packages/* as "workspaces", my guess is that each package is a workspace, thus workspaceRoot must refer to each package individually, while projectRoot must refer to a top-level dir with my nx.json config.因为package.json提到我的packages/*作为“工作区”,我的猜测是每个 package 都是一个工作区,因此workspaceRoot必须分别引用每个 package,而projectRoot必须引用我的nx.json配置的顶级目录。 But I have absolutely no idea how to confirm this.但我完全不知道如何确认这一点。 I'm experimenting with cache (setting various inputs as seeing is it hits or misses), and absolutely nothing works.我正在试验缓存(设置各种inputs ,看它是命中还是未命中),但绝对没有任何效果。

To clarify what I'm confused about: Is "workspace root" a directory containing all the workspaces (ie packages), or does it mean "root directory of an individual workspace (ie package)."澄清一下我的困惑:“工作空间根目录”是包含所有工作空间(即包)的目录,还是表示“单个工作空间(即包)的根目录”。 (Here I'm assuming that "workspace" == "package", which may not be true.) (这里我假设“workspace”==“package”,这可能不是真的。)

Based on reading https://nx.dev/concepts/mental-model , here are my definitions:基于阅读https://nx.dev/concepts/mental-model ,这里是我的定义:

  • "project" = each package, eg a library or an app, which refers to each individual subdirectory inside packages/ "project" = each package,例如一个库或一个应用程序,它指的是packages/中的每个单独的子目录
  • "projectRoot" = root of each individual package. In the example from the question, it will be packages/package1 and packages/package2 “projectRoot”=每个人的根 package。在问题的示例中,它将是packages/package1packages/package2
  • "workspace" = collection of all the packages/projects. “工作区”=所有包/项目的集合。 Note that "package.json" uses the word "workspaces" (plural) to refer to a directory with all the packages, which is what confuses me.请注意,“package.json”使用单词“workspaces”(复数)来指代包含所有包的目录,这让我感到困惑。
  • "workspaceRoot" = the root directory where nx.json is located "workspaceRoot" = nx.json所在的根目录

In short:简而言之:

  • project = package项目 = package
  • workspace = collection of projects工作空间 = 项目集合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM