1

I'm trying to change the backend of my React app to be only Flask based, instead of having two different servers ('npm' and 'flask').

The app was created with 'create-react-app' and the current folder structure is:

- myapp
  - node_modules
  - src
    - App.js
    - index.js
    - index.css
    - App.css
  - templates
    - index.html
  app.py
  package.json

The app.py file consists of this code:

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)

The thing is, until now on every save, the npm automatically bundled and reloaded all of my changes in the browser. Now, if I make a change, for example, in the 'index.html', the change is visible in the browser. However, if I try to edit my 'App.js', the change isn't visible at all.

From now on, do I need to rebundle the 'App.js' and components by myself everytime I save them?

I'm a bit confused about this one, so any help or advice would be highly appreciated.

1 Answer 1

2

When you finish the development process, you should run npm build it will create a new folder of static files, named build.

Then you can use any server to serve those static files.

If you want to make any changes, you should do again npm build and it will update the bundled version in the build folder

If you wish to use your backend server while developing, create-react-app isn't for you. You should do npm eject, and then you can do whatever you want

Sign up to request clarification or add additional context in comments.

1 Comment

This cleared my misunderstandings, thanks @Aminadav!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.