I am trying to follow:
https://medium.com/uva-mobile-devhub/set-up-react-in-your-django-project-with-webpack-4fe1f8455396
for webpack + django + reactjs
with the below directory structure
repodirectory/
├── mysite/
│ └── mysite/ # project
│ └── polls/ # app
│ └── static/
│ └── bundles/ # generated by webpack
│ └── js/
│ └── templates/
│ └── polls/
│ └── index.html/
│ └── questions.html/
│ └── manage.py
│ └── webpack-stats.json # generated by webpack
├── .babelrc
├── package.json
├── webpack.config.js
├── node_modules/ #contains our JS dependencies
I have two urls:
http://127.0.0.1:8000/polls/ -- uses index.html template
http://127.0.0.1:8000/polls/questions/ -- uses questions.html template
but i have only index.js in which i write the reactjs code
So how to write separate reactjs code for each url and then bundle it using webpack
Change
entry: './mysite/polls/static/js/index',
To
entry: {
main: './mysite/polls/static/js/index',
HomeApp: './mysite/polls/static/js/HomeApp',
},
in webpack.config.js and re-run npm run watch command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With