Gulp is JavaScript task runner. A task runner does what it sounds like. It performs tasks for you and Gulp is the engine that can run individual, predefined tasks.
These tasks could be just about anything from compiling Sass to CSS and serving these files in development, to minifying CSS and JavaScript to create smaller files for production environments.
We can see that a project has Gulp installed already, if it has a gulpfile.js.
This is the file that the Gulp engine will look for in defining all of the Gulp tasks, and it always lives in the root of your project.
Installing Gulp
Steps for using Gulp for the first time:
- Install NodeJS
- Install HTTP Server globally
- Create
package.json
file listing project’s Node dependencies. - Install Gulp and register it in
package.json
as a project dependecy - Install Gulp globally also
1. Install Node
Install NodeJS for Windows from here:
https://nodejs.org
Check if NodeJS has been successfully installed on Windows:
node -v
v8.4.0
npm -v
5.3.0
2. Install an HTTP Server
npm install -g http-server
Use -g
or --global
to install a package globally to use it system-wide.
View site via Node’s HTTP server on port 3000
http-server -p 3000
-p
stands for port.
3. Create Dependencies JSON File
Gulp is a Node module and in order to add gulp to our project, we have to create a package.json file that lists the project’s Node dependencies.
npm init
This will initialize your project’s folder as a Node package/project.
Now, package.json
file has been created on your project’s root folder.
4. Install Gulp
npm install gulp --save-dev
--save-dev
tells npm to add gulp to package.json
as a project’s development dependency.
Dependencies are how you and other developers know which Node modules should be installed with your project. Gulp of course is a development-only dependency, and is not needed to run our app/site.
5. Install Gulp Golbally
npm install -g gulp