Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django + webpack + reactjs: how to generate multiple pages by separate reactjs code for each url

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

like image 587
Santhosh Avatar asked Jun 13 '26 16:06

Santhosh


1 Answers

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