So, all tutorials and documentation on Ionic Framework tells you to install ionic and cordova globally (using “npm -g cordova” and “npm -g ionic”).
That is just so ugly. How am I supposed to use different versions in different project, and what if I don’t have sudo accesss?!
Just installing ionic and cordova locally (skipping the -g parameter) does not work, since ionic and cordova will not find each other. So ionic and cordova must be in your PATH, but again, that will lead to headache when dealing with multiple project with different versions of ionic/cordova.
My solution to this is to start all projects with a Makefile, which keeps track of the PATH for the project, and put the ionic/cordova commands that I use into that Makefile. Something like this:
SHELL := /bin/bash
export PROJDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
export PATH := $(PROJDIR)/node_modules/.bin:$(PATH)
if [ "$$(which cordova)" = "" ]; then npm install cordova; fi
if [ "$$(which ionic)" = "" ]; then npm install ionic; fi
ionic start app tabs
mv app/* app/.[^.]* .
rm -Rf node_modules
So, first run “make deps” to install cordova and ionic into your local node_modules/.
Then “make start” to create the project. Note that this make command will actually create the project in a subdirectory and then copy it into the same directory as your Makefile. (The ionic command line does not support “ionic start .” for creating a project in the current directory.)
Now you can “make serve”, or add other ionic commands into your Makefile.