I successfully deployed my Django project to Heroku. But I want to be able to automatically build React before deploying.
The React app is served through Django, so I have the bundled files of React in my templates and static folders of the Django app.
The project structure looks something like this:
react/
build/
components/
App.js
package.json
...
django/
templates/
static/
...
Procfile
requirements.txt
Pipfile
I have both the React and Django projects in the same repository and I want to run npm run build automatically before Django is deployed.
I set up the build script to move the bundled files from React to Django.
From what I've read, I need to add the NodeJS buildpack, but I don't know how to set it up to run before the Python buildpack.
Basically, the NodeJS process should just build my React app and then terminate. After that, the Python process should start up and deploy the Django project.
One solution to do this would be to use Docker and deploy that image to Heroku.
But, is there an easier way?