简体   繁体   中英

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 ?

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

{projectRoot} and {workspaceRoot}

{projectRoot} is a key word that is replaced by the path to the current project's root directory. {workspaceRoot} is a key word that is replaced by the path to the workspace root directory.

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. 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.

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.)

Based on reading https://nx.dev/concepts/mental-model , here are my definitions:

  • "project" = each package, eg a library or an app, which refers to each individual subdirectory inside packages/
  • "projectRoot" = root of each individual package. In the example from the question, it will be packages/package1 and packages/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.
  • "workspaceRoot" = the root directory where nx.json is located

In short:

  • project = package
  • workspace = collection of projects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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