Automate react shipping with Django with a simple command
Project description
Django-React Packager
React-Django packager helps you ship a react front end with django as backend. This package automatically builds your react project and places the static and index file in their appropriate place in your django project.
Installation
Install the package using pip:
pip install dr_packager
and thats it!
Motivation
React is one of the most popular front-end frameworks, and with django being one of the most popular backend choices, there are a lot of websites built with this stack. You can serve django on a different server than the react project and communicate between them using an API, but for smaller projects (or even bigger ones), Having 2 separate server is not justified. Copying react build files to your server is not fun either (which can be simplified with a CI\CD).
This project helps you serve react project with django (that can be deployed on a single server). This package was made out of frustration of building react project and manually copying everything to django project.
Usage
To use the packager, you should have both the react folder & django folder in the same parent folder as follows (Absolute path is still not supported in this version):
├───root_folder
│ ├───django_project
│ ├───react_project
Your django project should contain:
- An app that serves the
index.html
- A static folder (set by STATIC_ROOT variable in your settings)
IMPORTANT: Your django project root folder and base app should have the same name for example, settings.py should be located at
example.example.settings.py
Open terminal in root_folder
, and run the following command:
dr_package <react_path> <django_path> <django_front_app_name>
Following the above folder example, consider that we have an app named front
in our django project:
dr_package react_project django_project front
IMPORTANT: Your django settings files should contain STATIC_ROOT variable
Commands
usage: dr_package [-h] [-S] [--npm] [--yarn] [-D] [-I] [--folders-old [FOLDERS_OLD ...]]
react_path django_path app_name
Build React Project and Deploy with Django!
positional arguments:
react_path React folder name (RELATIVE PATH)
django_path Django folder name (RELATIVE PATH)
app_name Name of the app that holds index.html
optional arguments:
-h, --help show this help message and exit
-S, --skip-build Skip react build (Use what is alredy in \build\)
--npm use npm as the package manager of the react project
--yarn use yarn as the package manager of the react project
-D, --delete-old Delete old static files
-I, --install Run install command before building (use if you haven't installed the required packages)
--folders-old [FOLDERS_OLD ...]
Name of the folders to delete (Doesn't work if --delelete-old is not provided), separated by
space
Roadmap
- Support for absolute path
- Default setting file
- More customization
- Creating a separate django package (to run as management commands) to use with git hooks
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dr_packager-0.1.0.tar.gz
.
File metadata
- Download URL: dr_packager-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59c56700a61e3e561a81c870ea05e0319e60c58d9e4d1d6d0c2147191e14ae10 |
|
MD5 | 7ad122e8643cdb1a9c606632d061f076 |
|
BLAKE2b-256 | 0f3da55201744ed92026668e4c0198fb1bcf35fc20b06de7e1935eecc9c7efbb |
File details
Details for the file dr_packager-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: dr_packager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9653845e456e1775ce062634f76f8261a21c4d0784bad9ad968c9d8acf6e19d7 |
|
MD5 | 1a90c5b9700f744f4fc69fb9a6b48246 |
|
BLAKE2b-256 | 97f522b8bc74d7c94401709b549a565b19822b84b329b2be7003d8f6f7d98f17 |