Best way to serve npm packages with django?

Viewed 339

I am using django as a backend with a few js packages installed with npm. I am currently accessing the packages by allowing django to serve /node_modules by adding it to the STATICFILES_DIRS. This has been working, but I have to go in the pacakge and find the js file I want to point to and then load it using a <script src="{% static ....

This is a bit tedious and seems a bit "hacky." I also cannot figure out how to use imports/requires inside my js files. Is there a way to use imports or am I stuck loading everyting via script tags? I assume this is because django doesn't know how to server the npm packages appropriately? I've read a bit into webpack and I'm still unsure if webpack is a solution to my problem. Any advice?

1 Answers

I recommend learning/using Webpack.

I was trying to avoid using it, but it's a great tool to have in your development bag. Makes front-end development modular and simplistic.

Related