Dev Workflow
Frontend Infrastructure Diagram
Notes:
- The frontend app compile and bundle frontend assets.
- After it finish building, the built assets are placed at
STATIC
directory. - Django will treat the built assets as normal assets and do not care where they come from.
- Django will add the JS and CSS link to the template to make sure browser can download them.
When user visits the website:
- Web server process the request, render HTML using Django template.
- The browser download CSS, JS and other assets.
- The browser run Javascript to sprinkle the server-rendered HTML.
Frontend Project Structure
The frontend project was created by python-webpack-boilerplate
├── package-lock.json
├── package.json
├── postcss.config.js
├── tailwind.config.js
├── frontend
│ ├── README.md
│ ├── build
│ ├── src
│ │ ├── application
│ │ ├── components
│ │ ├── controllers
│ │ ├── helpers
│ │ └── styles
│ ├── vendors
│ └── webpack
Notes:
frontedn/build
directory contains all built static assetsfrontedn/src/application
contains entry application filefrontedn/src/controllers
contains Stimulus controllersfrontedn/src/helpers
contains helper Javascript.frontedn/src/styles
contains SCSS files.
npm run start VS npm run watch
Both commands will compile frontend assets, npm run start
will launch dev server which can auto refresh web page in some cases, while npm run watch
does not support this feature.
- https://python-webpack-boilerplate.readthedocs.io/en/latest/frontend/
- https://python-webpack-boilerplate.readthedocs.io/en/latest/live_reload/
After you compile the frontend assets, the javascript_pack
and stylesheet_pack
will help import the bundle files in Django template.
You can check django_app/templates/base.html to learn more.
Install package
If you want to install 3-party npm package, please use npm install
command