You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -105,7 +101,7 @@ This will generate the following file and directory structure underneath the ```
105
101
└─ hatch_project
106
102
├─ ...
107
103
├─ apps
108
-
│ ├─ react-store
104
+
│ ├─ hatch_project
109
105
│ │ ├─ public
110
106
│ │ │ └─ ...
111
107
│ │ ├─ src
@@ -123,7 +119,7 @@ This will generate the following file and directory structure underneath the ```
123
119
│ │ ├─ tsconfig.json
124
120
│ │ ├─ tsconfig.spec.json
125
121
│ │ └─ vite.config.ts
126
-
│ └─ react-store-e2e
122
+
│ └─ hatch_project-e2e
127
123
│ └─ ...
128
124
├─ nx.json
129
125
├─ tsconfig.base.json
@@ -149,7 +145,9 @@ This will generate the following file and directory structure underneath the ```
149
145
├─ nx.json
150
146
```
151
147
152
-
To support the nested directory structure correctly in your ```/hatch-project/src/hatch_project/nx.json```, you should adjust the paths to reflect the correct locations within the nested workspace. Here’s a revised example:
148
+
**IMPORTANT**: Modify **nx.json** so it can connect with Nx Cloud.
149
+
150
+
To support the nested directory structure correctly in your ```/hatch-project/nx.json```, you should adjust the paths to reflect the correct locations within the nested workspace. Here’s a revised example:
153
151
154
152
```json
155
153
{
@@ -230,24 +228,24 @@ To support the nested directory structure correctly in your ```/hatch-project/sr
230
228
}
231
229
}
232
230
```
233
-
/nx.json
231
+
repository-name/nx.json
234
232
235
233
### Key Adjustments:
236
234
-**`projects` section**: Explicitly defines the project structure, setting the `root` and `sourceRoot` to the correct paths within the nested directory.
237
235
- Ensure that all paths reflect the actual structure of your workspace.
238
236
239
237
This configuration will help Nx Cloud properly identify and manage your nested workspace.
240
238
241
-
Notice that it prepends paths with ```src/``` (e.g., ```"root": "src/hatch_project",```) to allow for our **nested** directory structure.
239
+
Notice that it prepends paths with ```hatch-project/src/``` (e.g., ```"root": "hatch-project/src/hatch_project",```) to allow for our **nested** directory structure.
242
240
243
241
The path for `root` in the `projects` section should be specified relative to the workspace root, which is typically the directory where your `nx.json` file is located.
244
242
245
-
Since your `nx.json` is at `repository-name/hatch-project/src/hatch_project/nx.json`, the paths are relative to the `src/hatch_project` directory. Thus:
243
+
Since your `nx.json` is at `repository-name/nx.json`, the paths are relative to the `hatch-project/src/hatch_project` directory. Thus:
246
244
247
-
-**`root`**: Should be `"src/hatch_project"` because it indicates the base directory for the project relative to the workspace's root.
248
-
-**`sourceRoot`**: Should be `"src/hatch_project/src"` for the same reason.
245
+
-**`root`**: Should be `"hatch-project/src/hatch_project"` because it indicates the base directory for the project relative to the workspace's root.
246
+
-**`sourceRoot`**: Should be `"hatch-project/src/hatch_project/src"` for the same reason.
249
247
250
-
If you were to use the absolute path `hatch-project/src/hatch_project`, it would not be correct in the context of how Nx expects paths to be defined. Nx uses paths relative to the workspace root to maintain consistency across different environments and setups.
248
+
If you were to use the absolute path `hatch-project/src/hatch_project`, it would not be correct in the context of how Nx expects paths to be defined. Nx uses paths relative to the workspace root to maintain consistency across different environments and setups.**Note**: In our case the path is from the root of the repository so there is no difference in relative or absolute path.
251
249
252
250
### Key Sections:
253
251
-**`npmScope`**: Defines the scope for your packages.
@@ -257,54 +255,56 @@ If you were to use the absolute path `hatch-project/src/hatch_project`, it would
257
255
258
256
Adjust paths and options as necessary to fit your specific project structure. This configuration will help Nx Cloud identify and manage your workspace correctly.
259
257
260
-
Make sure to run the **build** command from the `/hatch-project/src/hatch_project` directory - which contains the ```nx.json``` file - to ensure it recognizes the workspace correctly:
258
+
Make sure to run the **build** command from the root of the repository - which contains the ```nx.json``` file - to ensure it recognizes the workspace correctly:
259
+
261
260
```
262
-
$ cd /hatch-project/src/hatch_project
261
+
$ cd / # Go to the root of the repository
263
262
$ nx build hatch_project
264
263
```
265
264
266
265
**Important**:
267
266
268
267
If you don't have `workspace.json` or `project.json`, and instead have `tsconfig.base.json`, you can adjust your setup as follows:
269
268
270
-
* Option: Single Application: **Create a `workspace.json`**: If your project is a single application, you can create a `workspace.json` file in the `hatch_project` directory. Here’s a basic example:
271
-
272
-
```json
273
-
{
274
-
"version": 1,
275
-
"projects": {
276
-
"hatch_project": {
277
-
"root": "src/hatch_project",
278
-
"sourceRoot": "src/hatch_project/src",
279
-
"projectType": "application"
280
-
}
281
-
}
282
-
}
283
-
```
269
+
* Option: Single Application: **Create a `workspace.json`**: If your project is a single application, you can create a `workspace.json` file in the root of the repository. Here’s a basic example:
* Option: Multiple Applications: If your Nx workspace contains multiple applications, you should structure your `workspace.json` (or `project.json`) to reflect each application. Here’s how to set it up:
286
286
287
287
### Example `workspace.json`
288
288
289
-
Create a `workspace.json` file in the `hatch_project` directory with the following structure:
289
+
Create a `workspace.json` file in the root of the repository with the following structure:
After setting up `workspace.json`, you can run commands like:
@@ -346,43 +376,70 @@ nx build app1
346
376
nx build app2
347
377
```
348
378
349
-
**Note**: `workspace.json` and `project.json` serve different purposes in an Nx workspace:
379
+
This structure will help Nx Cloud recognize and manage multiple applications effectively.
350
380
351
-
### `workspace.json`
352
-
-**Purpose**: It defines the overall structure of the Nx workspace.
353
-
-**Content**: Contains configurations for all projects within the workspace, including their paths, types, and any shared settings.
354
-
-**Usage**: Typically used in monorepos with multiple projects to manage and organize them centrally.
381
+
This structure should allow Nx Cloud to detect the workspace properly.
355
382
356
-
### `project.json`
357
-
-**Purpose**: It defines the configuration for an individual project within the workspace.
358
-
-**Content**: Contains specific settings, targets (like build, test, lint), and options for that particular project.
359
-
-**Usage**: Used when you want to modularize project configurations, allowing each project to have its own settings while still being part of the larger workspace.
383
+
Run the command to **connect** your workspace to Nx Cloud from the root of the repository, specifically:
360
384
361
-
### Summary
362
-
-**`workspace.json`**: Central configuration for the entire workspace.
363
-
-**`project.json`**: Specific configuration for individual projects.
385
+
```
386
+
$ cd /../../../
387
+
$ npm init -y # If no package.json exists
388
+
# Go through the initialization steps
389
+
$ npm install -g nx@latest # If not already installed
In practice, you might use one or both depending on how you structure your Nx workspace. In newer versions of Nx, using `project.json` for individual projects is becoming more common.
396
+
Now commit these changes to GitHub repository before continuing!
366
397
367
-
This structure will help Nx Cloud recognize and manage multiple applications effectively.
398
+
The command to connect to Nx Cloud is:
368
399
369
-
This structure should allow Nx Cloud to detect the workspace properly.
400
+
```
401
+
$ nx connect-to-nx-cloud
402
+
```
403
+
404
+
This will initiate the configuration process for Nx Cloud within your workspace.
370
405
371
-
Run the command to **connect** your workspace to Nx Cloud from the root directory of the nx monorepo `hatch project`, specifically:
406
+
You will be prompted as follows:
372
407
373
408
```
374
-
$ cd /hatch-project/src/hatch_project/
409
+
NX ✔ This workspace already has Nx Cloud set up
410
+
411
+
If you have not done so already, connect your workspace to your Nx Cloud account with the following URL:
412
+
413
+
https://cloud.nx.app/connect/Ehf8PFoDWR
375
414
```
376
415
377
-
The command to connect to Nx Cloud is:
416
+
Finish the CI setup by visiting: https://cloud.nx.app/connect/eXwFUcpdBt # **Note**: the URL will differ per creation. See [Enable GitHub PR Integration](https://nx.dev/ci/recipes/source-control-integration/github) and/or watch [PNPM-CI: Connect Your Workspace to Nx Cloud for Enhanced Collaboration](https://www.youtube.com/watch?v=8mqHXYIl_qI).
417
+
418
+
419
+
The message "A workspace has already been assigned to this Nx Cloud connection" means that:
420
+
421
+
1. Your workspace is already configured with an Nx Cloud ID
422
+
2. That ID is already in use by another workspace
423
+
424
+
To fix this:
425
+
426
+
1. Check your current nx.json for the existing nxCloudId:
427
+
- Look for a line like: "nxCloudId": "67a3783761d0514ff26bf202"
428
+
- This ID needs to be unique for each workspace
429
+
430
+
2. Generate a new connection:
378
431
379
432
```
433
+
$ nx generate @nx/workspace:disconnect-cloud
380
434
$ nx connect-to-nx-cloud
381
435
```
382
436
383
-
This will initiate the configuration process for Nx Cloud within your workspace.
437
+
This will:
438
+
- Remove the existing cloud connection
439
+
- Generate a new, unique connection
440
+
- Provide you with a fresh URL to connect
441
+
384
442
385
-
Finish the CI setup by visiting: https://cloud.nx.app/connect/lvaFjW0bDV # **Note**: the URL will differ per creation. See [Enable GitHub PR Integration](https://nx.dev/ci/recipes/source-control-integration/github) and/or watch [PNPM-CI: Connect Your Workspace to Nx Cloud for Enhanced Collaboration](https://www.youtube.com/watch?v=8mqHXYIl_qI).
386
443
387
444
## Nested app directories
388
445
@@ -399,3 +456,15 @@ For example to ignore any files in ```.next```:
399
456
```
400
457
.nxignore
401
458
459
+
460
+
Now to run a build, run the following command from the root of the repository:
461
+
462
+
```
463
+
npx nx run-many -t build
464
+
```
465
+
466
+
To run a build for all applications, run the following command from the root of the repository:
0 commit comments