hexvolt / budget

0 stars 0 forks source link

Setup basic react app and integrate it to django app #12

Closed hexvolt closed 7 years ago

hexvolt commented 7 years ago
hexvolt commented 7 years ago

good article about the reasons of static files being handled by appropriate tools: http://owaislone.org/blog/modern-frontends-with-django/

hexvolt commented 7 years ago

http://owaislone.org/blog/webpack-plus-reactjs-and-django/

however, all the installation and configs of tools like webpack, webpack-bundle-tracker, babel, etc is done by initiating a template:

npm install -g create-react-app
create-react-app frontend

UPDATE: create-react-app has a lot of opaque configs and is intended to be used with npm backend server runned on 3000 port. There are no bundles generated automatically (they are generated on disk only when we build for production), as far as I understand, in dev mode webpack is preconfigured to keep them away from project folders. And the webpack output is retrieved by npm loclalhost:3000 server.

In order to sew it with django people setup the redirects from localhost:3000 to localhost:8000 and cope with CORS problems by writing a middleware, but that's ugly. From the outset, it was planned to use a single backend for serving both the API and for the initial index.html page + bundle.js.

We will use webpack in dev environment only and treat its output bundle.js as a static file which need to be delivered to production. In this way we avoid the overhead of setting up the npm and webpack on remote server for making a frontend build there.

For these reasons, I'd rather stick to transparent and manual configuration, following this aaproach http://owaislone.org/blog/webpack-plus-reactjs-and-django/

hexvolt commented 7 years ago

NOTE: Lot of outdated info in the articles and blogs. See the webpack.config.js in the repo (done according to latest docs)