While developing any JavaScript project it includes processes such as testing, minification, concatenating files, compiling templates. This is most error prone and tedious task. What if you have a build tool to automate all these repetitive tasks for you. One of such tools is Gulp.
What is Gulp ?
In one word: AUTOMATION.
Gulp is a stream build system which automates common tasks such as:
- Compiling your pre-processed CSS.
- Minifying JavaScript.
- Reloading your browser.
- Compile LESS files into CSS.
- Refreshing your browser automatically when you save a file.
- Optimizes all assets (CSS, JS, fonts, and images) for production
Gulp is publicly available on npm: https://www.npmjs.com/package/gulp and can also be found on Github: https://github.com/gulpjs/gulp.
Installing gulp:
https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md
You need to have Node.js (Node) installed onto your computer before you can install Gulp.
Install gulp globally:
$ npm install –global gulp
Install gulp in your project devDependencies:
$ npm install –save-dev gulp
Writing your first gulp task:
Step 1:
Create a gulpfile.js at the root level of your project.
Step 2:
Require gulp in your gulpfile.
var gulp = require(‘gulp’);
Step 3:
Write your task with this gulp variable.
gulp.task(‘task-name’, function() {
// Stuff here
});
task-name
refers to the name of the task, which would be used whenever you want to run a task in Gulp. You can also run the same task in the command line by writing – gulp task-name
To test this, let’s create a hello task in your gulpfile that says Hello World!
gulp.task(‘hello’, function() {
console.log(‘Hello World!’);
});
Now run this task in the command line with: gulp hello
The command line will print a log that says Hello World!
So any problem as a JavaScript developer during automation? Just GULP it.
Hey nice article but still i have some confusion. Is it possible to use gulp without node.
LikeLiked by 2 people
Hi.. thank you. You cannot use gulp without node because gulp is a node.js based task runner. It is a package of node and hence needs node to execute it. I hope this solves your confusion.
LikeLiked by 1 person
Interesting post! Thanks for writing it 🙂
LikeLiked by 1 person
Thank you. Happy to share 🙂
LikeLike
Hey nice posts…learned a few things which i didnt knew…thks nikita ma’am for sharings knowledge…
LikeLiked by 1 person
Thank you Jay. Hope it was helpful.
LikeLike