Gulp Cleaning Unwanted Files Gulp

How Gulp is used to clean unwanted files?

In this tutorial, we will learn on how to optimize CSS and JavaScript. The reason why optimizing is required is to remove the unwanted data (for e.g. spaces and unused characters) from the source files. This reduces the size of the files and lets them load faster

Install Plugins to Optimize CSS and JavaScript

Go to “work” directory from command line and then install “gulp-uglify”, “gulp-minify-css” and “gulp-concat” plugins by using the below command −

Declare Dependencies and Create Tasks

In our configuration file , I.e gulpfile.js, firstly we need to declare the dependencies as shown in the below code.

After declaration, we need to create tasks for optimizing CSS and JavaScript as shown in the below code.

The js task will accept the .js files from src/scripts/ folder. It concatenates and uglifies the js files, then produces build/scripts/script.js file.

And CSS task accepts the .css files from src/styles/ folder. This concatenates and reduces the CSS files, and produces build/styles/styles.css file.

Run the Tasks

Once the configuration file is set up , it is ready to execute.

We can use the below commands to run the task.

In the command Prompt, we will receive the following result:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Gulp Topics