How To Exclude node_modules Directory When Running collectstatic Command in Django

If you use npm or yarn to install frontend packages inside your Django project, you may notice, that when you run python manage.py collectstatic command, it ends up collecting huge amounts of files.

That's because by default, collectstatic grabs all content of static directories inside the project, including thousands of files that live inside node_modules directories produced by npm and yarn. 

Luckily, it's straightforward to omit node_modules directories altogether; just run your collectstatic command with an additional "ignore" argument, like this:

1
  1. python manage.py collectstatic -i node_modules

And you're done!

P.S. If you're tired of typing python manage.py everytime you need to run Django command, I recommend you to check a little package of mine called "Django manage.py anywhere": https://github.com/timonweb/Django-manage.py-anywhere, it'll surely save you some keystrokes here and there.