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.
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:
- install it
pnpm install @nxlv/python --save-dev
- update nx.json:
{
...
"plugins": [
"@nxlv/python"
]
...
}
- create project
nx generate @nxlv/python:poetry-project myproject
- Before that I needed to install
pipx
andpoetry
- in Arch in installed
pipx
withsudo pacman -S python-pipx
- ensure
pipx
is in path withpipx ensurepath
- restart terminal
- install
poetry
withpipx install poetry
- boom 🚀 ready to go!
- Before that I needed to install
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.
Comments ()