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 npm run dev followed by python manage.py runserver to start your local development server, just 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.3.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.3.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_npm_dev-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 87d84e84d6d4493e23452ab6dd6bb11dcf70092e659c1bbeb6cb7d256e570eb2
MD5 e42730c23604ee932a278b15b6cfdbb4
BLAKE2b-256 420722b70cf193ab3b6d455a63e80084d8d765525f5f9ccfac371eb54a2e91fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_npm_dev-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f04b6039c6e7da9812ffa81a71c42594652b245ea0d2b03dcc9793f5b7ca4e7
MD5 e6515094ad36690d833dda82d7e54a0f
BLAKE2b-256 fbfb2de9bea1e9125fbbc2f872a439475fa244f8310b5277a332ee49bafef467

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