Skip to main content

django management command to launch npm run dev and manage.py runserver in one shot

Project description

django_npm_dev

When you're using a tool like vite, webpack, or even just TailwindCSS and PostCSS to package frontend assets that require a build step with your Django site, you frequently need to start a separate development server using npm run dev whenever you're using the Django development server to work locally.

django_npm_dev provides a Django management command that starts that npm dev server in a separate thread and then starts Django's development server. Stopping Django's development server in any of the usual ways will also stop the npm dev script.

Frequently, I'm happy to just use a bash script like this one. When I need to hand a project to someone who works on Windows, though, that becomes a challenge. I also find that IDEs (and especially their built-in debuggers) work more smoothly with Django management commands than they do with shell scripts, in my experience.

Installation and Usage

Add django-npm-dev to your project using pip or your favorite package management tool.

pip install django-npm-dev
uv add django-npm-dev

Then add django_npm_dev to your INSTALLED_APPS in your site's settings.py

INSTALLED_APPS = [
    ...,
    'django_npm_dev',
    ...,
]

Now, instead of running python manage.py runserver to start your local development server, run python manage.py dev runserver.

Tips

If you're using Vite, and you make changes to django templates in addition to assets built by Vite, you should use install django-browser-reload so that django template changes trigger a reload as well as changes to Vite-managed assets.


If NPM isn't on your path, specify the path to your NPM command in settings.py:

NPM_BIN_PATH=/opt/local/bin/npm

Credits

Reading Cory Zue's article about using Vite with Django and his comment when I suggested that this might fit with the starter he published as a companion made me think it belonged in its own package.

The NPM wrapper is an adapted version of the one from django-tailwind.

License

All original code in this repository is copyright 2025 Geoff Beier geoff@tuxpup.com. It's offered under the same MIT LICENSE as the NPM wrapper that I adapted from django-tailwind. Any other code distributed with this repository remains under copyright by its authors, and is used under their respective licenses.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_npm_dev-0.2.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_npm_dev-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file django_npm_dev-0.2.0.tar.gz.

File metadata

  • Download URL: django_npm_dev-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.0

File hashes

Hashes for django_npm_dev-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a9c56cf9252547ad2fd8b85e8400cfb0f89c39d3284a3cbc744813a7bfdaaac
MD5 cc42dd3a09f2f4c0dca7823fb7e972eb
BLAKE2b-256 100a2b65a8654051b64a746b7360e3bb49dc89717bceb38a75942bf7a03c476e

See more details on using hashes here.

File details

Details for the file django_npm_dev-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_npm_dev-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6da2b2f47ef88bbc59109ba00d7cd4f247eec4bce0a34e2c5aad84e8eb4ec843
MD5 8d05f75f3fbe51549a4a614e6d853ceb
BLAKE2b-256 5205c00efe5439e7695305ecd2e6752834cdb7db83deb06a3714d69a08d777cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page