Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can manage.py runserver execute npm scripts?

Tags:

I am developing a web application with React for frontend and Django for backend. I use Webpack to watch for changes and bundle code for React apps.

The problem is that I have to run two commands concurrently, one for React and the other one for Django:

webpack --config webpack.config.js --watch
./manage.py runserver

Is there any way to customize runserver command to execute the npm script, like npm run start:dev? When you use Node.js as a backend platform, you can do the similar job like npm run build:client && npm run start:server.

like image 998
Ming Soon Avatar asked Feb 27 '17 22:02

Ming Soon


1 Answers

If you are already using webpack and django, probably you can be interested in using webpack-bundle-tracker and django-webpack-loader.

Basically webpack-bundle-tracker will create an stats.json file each time the bundle is build, and django-webpack-loader will watch for those stats.json file to relaunch the dev server. This stack allows to separate the concerns between the server and the client.

There are a couple of posts out there explaining this pipeline.

like image 100
Francisco Puga Avatar answered Sep 21 '22 11:09

Francisco Puga