A dead simple Flask-React app that's easy to deploy to Heroku. Clone this repo and modify it for your own use.
I built this boilerplate because I could find only limited advice on the web on creating a Flask app with a React frontend that could be deployed to Heroku.
The project includes ESLint and the Bulma CSS framework. Parcel.js is used to bundle the JS.
View live project on Heroku.
Inspired by:
- Miguel Grinberg's 'How to Create a React + Flask Project' and 'How to Deploy a React + Flask Project' tutorials.
- Anindita Basu's flask-heroku-start-pack and tutorial.
- Ayushman Kumar's 'Deploy Python Flask App on Heroku' tutorial
- Python v3.8+
- Node v6+
To install, clone this repo and cd into the root of the project.
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment. If you're using a Unix-based OS, run:
source venv/bin/activate
If you're using Windows, run:
venv\Scripts\activate
- Install the needed python dependencies:
pip install -r requirements.txt
- Now enter the following command to install the required Node packages:
npm install
To spin up a local Flask server with the latest build of the frontend, run:
npm run flask:prod
For development, you may prefer to spin up a local server with your Flask app and a separate local server with your React app. Run:
npm run flask:dev
In either case, you should be able to view the app at 127.0.0.1:5000
Note: You may need to hard refresh your browser as you develop in order to see changes to your frontend.
To spin up Parcel's dev server with just your React frontend, run:
npm run start
You should be able to view the project at localhost:1234
Note: Keep in mind you will not be able to interact with the server unless you also spin up your Flask app. However, it can sometimes be preferable to develop using Parcel's dev server, rather than Flask's, because Parcel includes hot reloading by default.
These instructions assume you have a Heroku account and that you've initialized this project as a new repo.
For your initially deployment, run the following commands from inside your project:
- Log in to Heroku if you're not already logged in:
heroku login
- Create a new Heroku project with a unique name. Upon execution, Heroku will add the location of this project to git as a new remote repo.
heroku create dsr-flask-react-app
- Now push your code to Heroku:
git push heroku master
For subsequent deployments to Heroku, make sure you're on your master branch then run:
npm run deploy