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 #2

Closed
wants to merge 17 commits into from

Conversation

LoTerence
Copy link
Owner

@LoTerence LoTerence commented Aug 30, 2024

Fixes hackforla#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

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

  • 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 in production.

Changes by file:

  • ./.dockerignore - added the production build and tidied up a bit
  • ./.gitignore - ignore the vite static assets build
  • 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.

@LoTerence LoTerence changed the title Feat/django vite ✨Feature: Vite HMR in development mode + Vite backend django integration Aug 30, 2024
@LoTerence LoTerence closed this Oct 2, 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.

1 participant