Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Feature: Vite HMR in development mode + Vite backend django integration #564

Merged
merged 17 commits into from
Sep 13, 2024

Conversation

LoTerence
Copy link
Member

@LoTerence LoTerence commented Aug 30, 2024

Fixes #563

  • Goal: enable vite HMR in development mode.
  • With this PR, the frontend should be fully migrated from webpack to vite.
  • The only thing left to do is remove all the webpack files and code.

Changes

Big changes:

Try it yourself

How to run the new full stack CivicTechJobs application in development mode?

  1. Simply run the following command in the root directory to start the application in dev mode:
docker compose -f docker-compose.dev.yml up --watch
  1. Wait for docker compose to finish building and running the containers. There should be 3 containers: pgdb, django, and vite.
  2. Navigate to http://localhost:8000 in your browser
  3. Now try changing text in frontend/src/pages/LandingPage/LandingPageIntro.tsx
  4. Watch the text on the page reload in less than a second 🚀

How does the new vite backend integration work?

Vite dev server

  • Running $ vite dev inside the /frontend directory will start a vite development server with fast Hot Module Reload enabled.
  • The django settings.py file is configured to load js modules from the dev server in DEBUG mode (aka dev mode).
  • It does so with the help of the django-vite PyPI package.
  • django-vite is set to fill in your index.html template with vite js modules for you.

Production bundle - NEEDS REVIEW

  • Running $ vite build inside the /frontenddirectory will create a build directly in the django backend.
  • The static assets are saved into a folder called backend/vite_assets_dist.
  • Django will serve this build as static assets in production.
  • THIS NEEDS REVIEW FROM THE TEAM - I have no idea how static assets are served in production at the moment. I would be happy to change this to suit whatever process you guys had in place before.

Changes by file:

  • ./.dockerignore - added the vite build files and tidied up a bit
  • ./.gitignore - ignore the vite build files
  • backend/settings.py - configured environment variables and set up django-vite integration
  • backend/urls.py - add a path for the new index.html template
  • backend/poetry.lock - added django-vite and python-decouple packages
  • backend/pyproject.toml - added django-vite and python-decouple packages
  • backend/templates/index.html - moved the index.html template from the frontend to the django backend, where it makes more sense to keep.
  • dev/django.Dockerfile - new dockerfile for building the django dev environment docker image
  • dev/vite.Dockerfile - new dockerfile for building the vite development server docker image
  • ./docker-compose.dev.yml - new compose file for running the application in development mode
  • frontend/.gitignore - ignore vite.config.mts.timestamp... - this temp file is created when you run $ vite dev, but sometimes it does not get removed after.
  • frontend/package.json - remove vite-plugin-html package, it is no longer needed
  • frontend/package-lock.json - remove vite-plugin-html package, it is no longer needed
  • frontend/src/index.tsx - import vite/modulepreload-polyfill - necessary for vite backend integration.
  • frontend/src/templates/vite-index.html - removed this file as it is no longer needed
  • frontend/vite.config.mts - configured vite settings to integrate with django backend and docker compose.

Screenshots, if applicable

No changes to the website's appearance.

@JimmyJuarez10 JimmyJuarez10 requested review from JimmyJuarez10 and removed request for Anahisv23 and RojaPinnamraju September 13, 2024 03:24
Copy link
Member

@JimmyJuarez10 JimmyJuarez10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on 09/12 Meeting

@LoTerence LoTerence merged commit 2c4e602 into hackforla:develop Sep 13, 2024
@LoTerence LoTerence deleted the feat/django-vite branch October 2, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants