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.1.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.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_npm_dev-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 026ebdf6a2c73cba744d2383277c17c3e7da198d6add5ec28eefcb54f1ac48f8
MD5 e410cb0ca1c0f5f94258c328bd1902e1
BLAKE2b-256 2bf8b65aabaf0eeb404dfc808329259c16262d03d49a983588d66a1c10eb680a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_npm_dev-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef268c5bcab09eeb9fc6333fd7067a8af74eb2a6840886fb5195609df1c2e4ed
MD5 c6be72594ab766123206ff982fa6c39e
BLAKE2b-256 b282b870aa465663152d58d7fed6538cb3c264f2c2d56703e30a3af694ffa3f7

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