Nx monorepo react-python

I will show you how to create a Nx mono-repo for a for a react-python stack app it is easy to do by CLI and requires little effort.

Nx monorepo react-python
Photo by Namito Yokota / Unsplash

TL;DR

I will show you how to create a Nx mono-repo for a for a react-python stack app it is easy to do by CLI and requires little effort.

Create a nx mono-repo with nx cli 🎮

nx official docs to create a react mono-repo recommends this command:

npx create-nx-workspace@latest <app-name> --preset=react-monorepo

I run a more personalized one based on my preferences:

npx create-nx-workspace@latest --name=<app-name> --preset=react-monorepo --docker=true --packageManager=pnpm --bundler=vite --style=@emotion/styled --e2eTestRunner=playwright

above command specific to use pnpm as package manager, playwright for e2e test runner and vite bundler instead of Webpack

after running above command and if you doesn't have any errors you could navigate to the recent folder created for you app in my case musiik with cd musiik and run there nx serve musiik (change the name for a relevant one to you and ensure nx is globally installed with npm i -g)

If everything is going well you should to have something in localhost:4200 similar to:

Nice!

Adding Python project based on Poetry 🎭

lets search for the proper nx plugin in plugins section if you search for Python you will see the poetry plugin by following the link you will land in its github page where you will found the instructions:

  1. install it pnpm install @nxlv/python --save-dev
  2. update nx.json:
{
  ...
  "plugins": [
    "@nxlv/python"
  ]
  ...
}
  1. create project nx generate @nxlv/python:poetry-project myproject
    1. Before that I needed to install pipx and poetry
    2. in Arch in installed pipx with sudo pacman -S python-pipx
    3. ensure pipx is in path with pipx ensurepath
    4. restart terminal
    5. install poetry with pipx install poetry
    6. boom 🚀 ready to go!

This shows it creates a new python project in extractor folder.

Edit:

Above command will create a Python project named Extractor inside a folder named same, which is not convenient, to solve this you could specify the directory name by using the parameter --directory=<directory-name>, the command will be:

nx generate @nxlv/python:poetry-project extractor --directory=python-microservices

This will create the project inside a different folder name, which is more convenient.