HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>Gulp provides a large number of tools for easy file manipulation. We covered most of them in earlier lessons, but they all work on the files and don't do any conversions. For example, Gulp doesn't have a built-in function to translate SASS to CSS, which is what you want in a tool like this.</p>
1 <p>Gulp provides a large number of tools for easy file manipulation. We covered most of them in earlier lessons, but they all work on the files and don't do any conversions. For example, Gulp doesn't have a built-in function to translate SASS to CSS, which is what you want in a tool like this.</p>
2 <p>And there is no contradiction here; Gulp provides only a platform - a kernel, around which we can build various data manipulations.</p>
2 <p>And there is no contradiction here; Gulp provides only a platform - a kernel, around which we can build various data manipulations.</p>
3 <p>In this lesson, we will look at some plugins that help layout designers work with Gulp. We will see how to set them up and use them in our work.</p>
3 <p>In this lesson, we will look at some plugins that help layout designers work with Gulp. We will see how to set them up and use them in our work.</p>
4 <h2>Installing third-party plugins</h2>
4 <h2>Installing third-party plugins</h2>
5 <p>Third-party plugins for Gulp are the npm packages we know and love. Therefore, their installation is no different.</p>
5 <p>Third-party plugins for Gulp are the npm packages we know and love. Therefore, their installation is no different.</p>
6 <p>All you need to do is install the package and plug it in at the beginning of the<em>gulpfile.js</em>we created.</p>
6 <p>All you need to do is install the package and plug it in at the beginning of the<em>gulpfile.js</em>we created.</p>
7 <p>The most convenient option to search for packages is to use<a>npmjs.com</a>. For example, if you want to find a handler for SASS files, you can search for it with two keywords:</p>
7 <p>The most convenient option to search for packages is to use<a>npmjs.com</a>. For example, if you want to find a handler for SASS files, you can search for it with two keywords:</p>
8 <ul><li>gulp</li>
8 <ul><li>gulp</li>
9 <li>sass</li>
9 <li>sass</li>
10 </ul><p>Then we search for the most popular package. Why is it the most popular? Most likely, the developers of these packages wrote detailed documentation and fixed the most critical bugs. It's also essential to track when the package was last updated. Some packages work fine and don't need to be updated, but they are the exception rather than the rule. Often, frequent updates indicate that the developers are listening to feedback and fixing critical issues:</p>
10 </ul><p>Then we search for the most popular package. Why is it the most popular? Most likely, the developers of these packages wrote detailed documentation and fixed the most critical bugs. It's also essential to track when the package was last updated. Some packages work fine and don't need to be updated, but they are the exception rather than the rule. Often, frequent updates indicate that the developers are listening to feedback and fixing critical issues:</p>
11 <p>In most cases, you will need an interpreter or compiler in addition to the Gulp plugin. For example, to process SASS, not only do you need a special package for Gulp, but also a SASS package.</p>
11 <p>In most cases, you will need an interpreter or compiler in addition to the Gulp plugin. For example, to process SASS, not only do you need a special package for Gulp, but also a SASS package.</p>
12 <h3>Sass</h3>
12 <h3>Sass</h3>
13 <p>To handle files created with the SASS preprocessor, we have a package called<a>gulp-sass</a>. It is a popular package updated along with updates to the preprocessor itself. To use it, you need to install two packages:</p>
13 <p>To handle files created with the SASS preprocessor, we have a package called<a>gulp-sass</a>. It is a popular package updated along with updates to the preprocessor itself. To use it, you need to install two packages:</p>
14 <ul><li>sass - the main SASS compiler</li>
14 <ul><li>sass - the main SASS compiler</li>
15 <li>gulp-sass - the plugin for Gulp</li>
15 <li>gulp-sass - the plugin for Gulp</li>
16 </ul><p>You can install everything with a single command:</p>
16 </ul><p>You can install everything with a single command:</p>
17 <p>File processing is simple, so let's take the existing structure we are working with throughout the course and add SASS compilation to CSS. As mentioned, we do this in several steps. Let us plug in the package and add it to the `pipe' function chain:</p>
17 <p>File processing is simple, so let's take the existing structure we are working with throughout the course and add SASS compilation to CSS. As mentioned, we do this in several steps. Let us plug in the package and add it to the `pipe' function chain:</p>
18 <h3>Pug</h3>
18 <h3>Pug</h3>
19 <p>You can process Pug in Gulp using the popular plugin<a>gulp-pug</a>. Have you noticed that the most popular plugins even have similar names? :)</p>
19 <p>You can process Pug in Gulp using the popular plugin<a>gulp-pug</a>. Have you noticed that the most popular plugins even have similar names? :)</p>
20 <p>Installing follows the same approach as the gulp-sass plugin. We should install pug and gulp-pug packages to use them. We can do it in one line:</p>
20 <p>Installing follows the same approach as the gulp-sass plugin. We should install pug and gulp-pug packages to use them. We can do it in one line:</p>
21 <p>File processing also follows the structure you're familiar with open, process, and write the file. Let's combine the functions using a parallel within a single build task:</p>
21 <p>File processing also follows the structure you're familiar with open, process, and write the file. Let's combine the functions using a parallel within a single build task:</p>
22 <p>In most cases, additional parameters are available in the handler functions, such as pug() and sass() from the examples above, which allow you to make fine-tuned compilation settings. Always pay attention to the available parameters.</p>
22 <p>In most cases, additional parameters are available in the handler functions, such as pug() and sass() from the examples above, which allow you to make fine-tuned compilation settings. Always pay attention to the available parameters.</p>
23 <h3>Browser Sync</h3>
23 <h3>Browser Sync</h3>
24 <p>The<a>browser-sync</a>plugin, while not a handler in the usual sense, performs one of the most powerful functions in frontend development: automatically refreshing the browser window when we execute functions. You can choose which actions you want the refresh to perform.</p>
24 <p>The<a>browser-sync</a>plugin, while not a handler in the usual sense, performs one of the most powerful functions in frontend development: automatically refreshing the browser window when we execute functions. You can choose which actions you want the refresh to perform.</p>
25 <p>It is<em>browser-sync</em>that makes it possible to provide a conditional working environment where you don't have to worry about compiling files and updating your browser. Everything happens on the fly.</p>
25 <p>It is<em>browser-sync</em>that makes it possible to provide a conditional working environment where you don't have to worry about compiling files and updating your browser. Everything happens on the fly.</p>
26 <p>To use<em>browser-sync</em>, you install the package with the same name. It's not just for Gulp, but you can use it as a standalone package in any other project, so there is no dedicated Gulp version:</p>
26 <p>To use<em>browser-sync</em>, you install the package with the same name. It's not just for Gulp, but you can use it as a standalone package in any other project, so there is no dedicated Gulp version:</p>
27 <p>First, using the plugin, let's create a local server. To do this, connect the plugin and initialize it with the server parameter:</p>
27 <p>First, using the plugin, let's create a local server. To do this, connect the plugin and initialize it with the server parameter:</p>
28 <p>When tunning the server task, we start a specific local server, the root of which will be the<em>build/</em>, the directory of our project. After launching, you can go to the address specified in the Local or External:</p>
28 <p>When tunning the server task, we start a specific local server, the root of which will be the<em>build/</em>, the directory of our project. After launching, you can go to the address specified in the Local or External:</p>
29 <p>The browser-sync package has another powerful method, .stream(). It allows you to call the local server automatically and reload it. In most cases, we add this operation to the end of the function inside the pipe().</p>
29 <p>The browser-sync package has another powerful method, .stream(). It allows you to call the local server automatically and reload it. In most cases, we add this operation to the end of the function inside the pipe().</p>
30 <p>To demonstrate this, let's complete the example with SASS and Pug, handling by adding the line .pipe(browserSync.stream()) to the end of each function:</p>
30 <p>To demonstrate this, let's complete the example with SASS and Pug, handling by adding the line .pipe(browserSync.stream()) to the end of each function:</p>
31 <p>As a final step, you should add watchers to perform compilation when files are changed. But what's the best way to do it? A good option is to add watch() functions inside the server creation task, i.e., in the browserSyncJob(). It'll first start the server and then the watchers, which will keep track of all the changes to the files:</p>
31 <p>As a final step, you should add watchers to perform compilation when files are changed. But what's the best way to do it? A good option is to add watch() functions inside the server creation task, i.e., in the browserSyncJob(). It'll first start the server and then the watchers, which will keep track of all the changes to the files:</p>
32  
32