Running gulp without installing it globally

Gulp vs. package.json

While considering whether or not to migrate my build-steps into package.json exclusively, I thought about the pros/cons around using a task-runner like gulp as opposed to managing everything through package.json and npm scripts.

Ultimately, the big selling points for me about using gulp is its configurability and its cross-platform support. I develop on a mac, yet a majority of our clients use windows machines. There are some issues with some of the npm scripts on windows. Additionally, when you only install gulp locally, you have complete control over which version is installed – which can be very important when delivering your code to clients.

One of the issues I’ve found with gulp is the necessity of globally installing another package. It adds another hurdle to setting up the dev environment, which while small, adds up. That said, I’ve recently come across a method for running gulp without having to install it globally.

Check it out!

How it works

We’ll create our gulpfile.js just as we normally do. However, instead of running gulp commands from the command line, we’re going to create some NPM scripts and use those instead.

Include a similar “scripts” object in your package.json file:

"scripts": {
    "dev": "./node_modules/gulp/bin/gulp.js dev",
    "build": "./node_modules/gulp/bin/gulp.js build"

By utilizing the paths to gulp.js through node_modules, we bypass the necessity the install gulp globally.

Now in terminal, you simply run

npm run dev
npm run build
respectively. Add whatever gulp tasks you define in your gulpfile.

I’ve been using this method for a little while now and have really liked it so far! Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *