DEV Community

Cover image for How to setup Gulp with ES6
ashishmangla0
ashishmangla0

Posted on β€’ Edited on

2 1

How to setup Gulp with ES6

Gulp is a tool that runs on Node.js which helps us automate many development tasks, we can use it for automating slow and repetitive work.

How Gulp works

Gulp reads files as streams and pipes those streams to different tasks. These tasks are code-based and use plugins in order to build production files from source files.

Prerequisites

Node.js
npm

How to install Gulp

Install the gulp command line

npm install --global gulp-cli
Enter fullscreen mode Exit fullscreen mode

Create a new project directory and navigate into it

npx mkdirp my-project
Enter fullscreen mode Exit fullscreen mode
cd my-project
Enter fullscreen mode Exit fullscreen mode

Create a package.json file

npm init
Enter fullscreen mode Exit fullscreen mode

Install the gulp in your devDependencies

npm install --save-dev gulp
Enter fullscreen mode Exit fullscreen mode

Transpilation

we have to rename our gulpfile extention gulpfile.js to gulpfile.babel.js for Babel transpilation and have to install the @babel/register module.

How To Create Tasks in Gulp

Gulp gives two composition methods series() and parallel() ,Both Methods takes n numbers of task functions or composed operations. this two methods can be nested within themselves or each other to any depth.

Tasks in series() method

series() method is used when you we have to run tasks in order.

Example
import { series } from "gulp";
const funA = (cd) =>{
cb();
}
const funB = (cd) =>{
cb();
}
export default series(funA ,funB)
Enter fullscreen mode Exit fullscreen mode

Tasks in parallel() method

parallel() method is used when you we have to run tasks in concurrency.

Example
import { parallel } from "gulp";
const javascript = (cd) =>{
cb();
}
const css = (cd) =>{
cb();
}
export default parallel(javascript ,css)
Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

This post blew up on DEV in 2020:

js visualized

πŸš€βš™οΈ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! πŸ₯³

Happy coding!

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay