Pyloid-React-Boilerplate is a template for projects combining a React frontend with a Python backend. Here, we'll explain in detail the project setup, development, and build process.
Before starting the project, you need to install all necessary dependencies.
npm run init
This command performs the following tasks:
- Install npm packages
- Create a Python virtual environment (venv-pyloid)
- Install Python dependencies (based on requirements.txt)
The appropriate script is executed depending on the operating system.
During development, you can run both frontend and backend servers simultaneously with the following command:
npm run dev
This command performs the following tasks:
- Run the React frontend development server using Vite
- Run the Python backend server (src-pyloid/main.py)
The concurrently package is used to run both processes in parallel.
To build the project for production deployment, use the following command:
npm run build
This command performs the following tasks:
- TypeScript compilation (tsc -b)
- Frontend build using Vite
- Package the Python backend into an executable using PyInstaller
PyInstaller is a tool that converts Python applications into standalone executables. Pyloid Boilerplate uses different spec files for each operating system:
- Windows:
build-windows.spec
- Linux:
build-linux.spec
- MacOS:
build-macos.spec
These spec files specify which files to include and what options to use for PyInstaller.
- Dependency Analysis: PyInstaller analyzes the Python script and its dependencies.
- File Collection: It collects all necessary Python modules, libraries, and data files.
- Binary Generation: It packages the collected files into a single directory or a single executable file.
You can modify the build process to meet your project's specific requirements:
- Modify the scripts section in
package.json
- Modify PyInstaller spec files (e.g.,
build-windows.spec
,build-linux.spec
,build-macos.spec
) - Write additional build scripts if necessary
- Cross-platform Builds: You need to perform the build for each platform on the respective operating system.
- Environment Variables: You may need to set environment variables appropriately depending on the production environment.
This guide should help you understand the process of initializing, developing, and building a project using the Pylon Boilerplate. Backend packaging with PyInstaller simplifies deployment and facilitates dependency management.