make is a widely used and powerful tool for running common tasks in a project.
I often look at the Makefile
of a project in order to see how a project perform regular tasks such as running tests, compiling and starting db, etc.
Use Case 1
I want to run 2 local servers at the same time. I can run them on separate terminal windows but I don't want to do that. I'm a lazy developer and want to use one line solution.
For instance I want to run a python
backend server and javascript
front end server for live reload
— if there is any change in static assets like js
, css
, scss
etc..
# Makefile
django-server: ## Run the Django server
python manage.py runserver 8000
npm-server: ## Run npm server to live reload
npm run dev
You can run them concurrently like below:
$ make -j 2 npm-server django-server
Or you can use a target
for it as well:
# Makefile
servers:
make -j 2 npm-server django-server
django-server: ## Run the Django server
python manage.py runserver 8000
npm-server: ## Run npm server to live reload
npm run dev
Then run make servers
.
Use Case 2
I want to run a local server and open a browser related to it. I don't want to manually click my browser and type localhost:$PORT
.
Solution:
# Makefile
local-dev: django-server browser
django-server: ## Run the Django server
python manage.py runserver 8000
browser:
google-chrome --new-window http://localhost:8000
# or if you use firefox
# firefox --new-window localhost:8000
Then type make local-dev
.
All done.
Top comments (1)
I think you could achieve the same result just using the shell, as follows-
python manage.py runserver 8000 &
google-chrome --new-window localhost:8000 &
or more economically-
nohup python manage.py runserver 8000 &
nohup google-chrome --new-window localhost:8000 &
because you could then close the terminal