npm i -g nx pnpmpnpm installTo see all projects maintained in this monorepo run:
nx show projectsTo see all available targets to run for a project, run:
nx show project {package-name}To run any task from any package, run:
nx run {package-name}:{task-name}E.g. to start the dev environment of the react-maplibre project run:
nx run react-maplibre:storybookAlternatively, you can also use:
nx {task-name} {package-name}To run all tasks in parallel, use:
nx run-many -t {task-name}E.g. to start all storybooks in dev mode run:
nx run-many -t storybookTo generate a new application, use:
nx g @nx/react:application --directory=apps/my-app --name=my-app --no-interactive --e2eTestRunner=noneTo generate a new library, use:
nx g @nx/react:library --directory=packages/my-package --bundler=vite --name=my-package --importPath=@mapcomponents/my-package --no-interactiveAlternatively, install Nx Console to use the generator form.
Nx uses project.json for its own configuration—keep its name simple, like my-app.
For publishing, you need a package.json with the full package name, e.g., @mapcomponents/my-app.
Both files are needed, but serve different purposes.
Instead of using relative paths to import from other packages in this monorepo, you can use the package name as an alias.
Ensure that Nx added the alias correctly to the tsconfig.base.json file.
It should look like this:
{
"compilerOptions": {
"paths": {
"@mapcomponents/deck-gl": ["packages/deck-gl/src/index.ts"],
"@mapcomponents/ra-geospatial": ["packages/ra-geospatial/src/index.ts"],
"@mapcomponents/{app/package name}": ["path/{app/package name}/src/index.ts"]
}
}
}Also, don't forget to set the type to module in the package.json of the package you want to import from:
{
"name": "@mapcomponents/{app/package name}",
"version": "0.0.1",
"type": "module",
"...": "..."
}Then, you can import from other packages like this:
import { component } from '@mapcomponents/{app/package name}';You also need to ensure that the tsconfig.package/app.json file in the current package includes the other package.
Example:
{
// rest of the tsconfig.package/app.json
"include": ["src/**/*", "../path/to/package/src/**/*"]
}nx g @nx/react:storybook-configuration --project=my-package --generateStories=false --interactionTests=false --no-interactiveAdd a refs object to the .storybook/main.ts file in your host Storybook and add the links for the composed Storybooks.
You can adjust the composition based on the current development environment (e.g., development, production) as in the following example:
{
refs: (config, { configType }) => {
if (configType === 'DEVELOPMENT') {
return {
'react-maplibre': {
title: 'React MapLibreMap',
url: 'http://localhost:4400',
},
'deck-gl': {
title: 'Deck.gl',
url: 'http://localhost:4401',
},
'ra-geospatial': {
title: 'Ra Geospatial',
url: 'http://localhost:4402',
},
};
}
return {
'react-maplibre': {
title: 'React MapLibreMap',
url: 'https://mapcomponents.github.io/react-map-components-maplibre/react-maplibre/',
},
'deck-gl': {
title: 'Deck.gl',
url: 'https://mapcomponents.github.io/react-map-components-maplibre/deck-gl/',
},
'ra-geospatial': {
title: 'React Admin Geospatial',
url: 'https://mapcomponents.github.io/react-map-components-maplibre/ra-geospatial/',
},
};
};
}It is necessary to statically set a different port for each project in the project.json file of the respective project.
You need to statically set a different port for each project in the project.json file of the respective project.
{
"targets": {
"storybook": {
"options": {
"port": 4401 // set a different port than for the other projects
}
}
}
}This is the command to run all the Storybooks in composition mode locally and in parallel:
nx run storybook-composition:storybook-compositionThen, in a new terminal, run:
nx run storybook-composition:storybookIf a new Storybook is added, make sure to add it to the run command in the project.json under apps/storybook-composition/targets/storybook-composition/options/commands.
This is how it should look:
{
"targets": {
"storybook-composition": {
"executor": "nx:run-commands",
"options": {
"commands": [
"nx storybook deck-gl",
"nx storybook ra-geospatial",
"nx storybook my-new-storybook" // <--- Add new Storybooks here
],
"parallel": true
}
}
}
}Before running the command, go to the project.json and add the following to the "targets" parameter:
{
"targets": {
"build": {
"executor": "@nx/vite:build",
"options": {
"outputPath": "dist/packages/my-package"
}
}
}
}nx g @nx/react:cypress-component-configuration --project=my-package --build-target=my-package:build --no-interactiveBefore publishing change the out dir in the build setting of the vite.config.js to dist
{
// rest of the vite.config.js
"build": {
"outDir": "dist"
}
// rest of the vite.config.js`
}
Make sure not to forget this flag: --skip-publish
nx release --skip-publishMake sure to replace "This was a version bump only, there were no code changes." with the relevant changes in the CHANGELOG.md.
Keep your dependencies consistent across your monorepo using Syncpack:
npx syncpack list-mismatches npx syncpack fix-mismatchesGo to your package directory and run:
npx depcheck --skip-missing