HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-02-21
1 <p>Throughout this course, we'll be working with the<em>gulpfile.js</em>file. Remember the project structure:</p>
1 <p>Throughout this course, we'll be working with the<em>gulpfile.js</em>file. Remember the project structure:</p>
2 <p>layout-project/ ├── build/ ├── src/ │ ├── sass/ │ │ └── app.scss │ ├── pages/ │ │ ├── index.pug │ │ ├── sections/ │ │ │ ├── head.pug │ │ │ └── footer.pug ├── gulpfile.js ├── package.json └── node_modules/</p>
2 <p>layout-project/ ├── build/ ├── src/ │ ├── sass/ │ │ └── app.scss │ ├── pages/ │ │ ├── index.pug │ │ ├── sections/ │ │ │ ├── head.pug │ │ │ └── footer.pug ├── gulpfile.js ├── package.json └── node_modules/</p>
3 <p>Note that the file is in the<em>layout-project/</em>directory, not<em>src/</em>. These things are important because the file location affects how we specify paths. If you see that, the build isn't going well. When something is going wrong, first check the<em>gulpfile.js</em>file location and the paths written there. You may encounter this problem when you copy a file from another project.</p>
3 <p>Note that the file is in the<em>layout-project/</em>directory, not<em>src/</em>. These things are important because the file location affects how we specify paths. If you see that, the build isn't going well. When something is going wrong, first check the<em>gulpfile.js</em>file location and the paths written there. You may encounter this problem when you copy a file from another project.</p>
4 <p>We can roughly divide the entire<em>gulpfile.js</em>file into three parts:</p>
4 <p>We can roughly divide the entire<em>gulpfile.js</em>file into three parts:</p>
5 <ul><li>Connecting the necessary components for operation</li>
5 <ul><li>Connecting the necessary components for operation</li>
6 <li>Functions-tasks that define operations</li>
6 <li>Functions-tasks that define operations</li>
7 <li>Exporting tasks by default</li>
7 <li>Exporting tasks by default</li>
8 </ul><p>We don't need to emphasize this because these operations don't go in any other order :)</p>
8 </ul><p>We don't need to emphasize this because these operations don't go in any other order :)</p>
9 <p>This course will use JavaScript code. If you haven't studied this language, take the<a>Introduction to Programming</a>course. This course will teach you the language basics, learn functions, connect packages, and export functions. We will use all of this in Gulp.</p>
9 <p>This course will use JavaScript code. If you haven't studied this language, take the<a>Introduction to Programming</a>course. This course will teach you the language basics, learn functions, connect packages, and export functions. We will use all of this in Gulp.</p>
10 <p>Let's create our first task in Gulp:</p>
10 <p>Let's create our first task in Gulp:</p>
11 <p>What's going on here? We contain the core information in the firstTask function. It is the task that Gulp will be able to perform.</p>
11 <p>What's going on here? We contain the core information in the firstTask function. It is the task that Gulp will be able to perform.</p>
12 <p>Let us pay attention to the passed `done' argument. We don't need to worry about where it comes from and what it contains. The important thing for us is that it's a function we call at the end of a task to indicate that it is finished.</p>
12 <p>Let us pay attention to the passed `done' argument. We don't need to worry about where it comes from and what it contains. The important thing for us is that it's a function we call at the end of a task to indicate that it is finished.</p>
13 <p>The name of the task is up to you. There are no restrictions, but try to name it accurately. If you're working with CSS, you don't need to call the task<em>WindowsOmegaTask</em>. You can read more about naming in our blog:</p>
13 <p>The name of the task is up to you. There are no restrictions, but try to name it accurately. If you're working with CSS, you don't need to call the task<em>WindowsOmegaTask</em>. You can read more about naming in our blog:</p>
14 <ul><li><a>Perfect Code: Naming in Programming</a></li>
14 <ul><li><a>Perfect Code: Naming in Programming</a></li>
15 <li><a>Perfect Code: Naming Mistakes in Programming I</a></li>
15 <li><a>Perfect Code: Naming Mistakes in Programming I</a></li>
16 </ul><p>Within the task, you can perform various actions, not all of which need to be related to transformation. These can also be simply informative tasks, as in the example above. We only have the console.log() output in this task. The lack of restrictions allows you to break up large functions and make the code easy to read.</p>
16 </ul><p>Within the task, you can perform various actions, not all of which need to be related to transformation. These can also be simply informative tasks, as in the example above. We only have the console.log() output in this task. The lack of restrictions allows you to break up large functions and make the code easy to read.</p>
17 <p>For Gulp to be able to run a task, we need to export it:</p>
17 <p>For Gulp to be able to run a task, we need to export it:</p>
18 <p>In this example, the export is named default. And this is indeed the default task that Gulp performs if you run the gulp command in the project directory.</p>
18 <p>In this example, the export is named default. And this is indeed the default task that Gulp performs if you run the gulp command in the project directory.</p>
19 <p>When performing a task, Gulp shows not only the result but also additional information:</p>
19 <p>When performing a task, Gulp shows not only the result but also additional information:</p>
20 <ul><li>The<em>gulpfile.js</em>file from which we run the task</li>
20 <ul><li>The<em>gulpfile.js</em>file from which we run the task</li>
21 <li>The name of the task (in this example, it is<em>default</em>)</li>
21 <li>The name of the task (in this example, it is<em>default</em>)</li>
22 <li>The task completion time</li>
22 <li>The task completion time</li>
23 </ul><h2>Exporting tasks</h2>
23 </ul><h2>Exporting tasks</h2>
24 <p>We don't have to use only default in our naming. You can use any name and export different tasks with different names. Let us refine the example a bit:</p>
24 <p>We don't have to use only default in our naming. You can use any name and export different tasks with different names. Let us refine the example a bit:</p>
25 <p>We added a few new things in this example. Let us take a closer look at them:</p>
25 <p>We added a few new things in this example. Let us take a closer look at them:</p>
26 <p>Here we can find the parallel() function from the Gulp package. This function allows you to combine several functions into one task.</p>
26 <p>Here we can find the parallel() function from the Gulp package. This function allows you to combine several functions into one task.</p>
27 <p>It is the parallel() function for exporting tasks in this example:</p>
27 <p>It is the parallel() function for exporting tasks in this example:</p>
28 <p>This example exports three tasks.</p>
28 <p>This example exports three tasks.</p>
29 <p>The default task performs three functions:</p>
29 <p>The default task performs three functions:</p>
30 <ul><li>sassCompile()</li>
30 <ul><li>sassCompile()</li>
31 <li>pugCompile()</li>
31 <li>pugCompile()</li>
32 <li>imagesOptimize()</li>
32 <li>imagesOptimize()</li>
33 </ul><p>To start the task, run gulp:</p>
33 </ul><p>To start the task, run gulp:</p>
34 <p>The layoutCompile task only calls functions related to the compilation of layout files. The gulp layoutCompile command runs it:</p>
34 <p>The layoutCompile task only calls functions related to the compilation of layout files. The gulp layoutCompile command runs it:</p>
35 <p>The assetsOptimize task calls the imagesOptimize() function. The gulp assetsOptimize command runs it:</p>
35 <p>The assetsOptimize task calls the imagesOptimize() function. The gulp assetsOptimize command runs it:</p>
36  
36