Guide on how to beautify HTML and generate output files in the identical directory as the current one

Hey there! I'm currently working as a junior front-end developer and have recently delved into using gulp. One of the challenges I face is dealing with HTML files received from senior developers that aren't well-formatted, containing excessive whitespace and poor indentation. Here's an example:

<div id="preloader">

        <div id="status">&nbsp;</div>

    </div>

    <div id="nav-anchor"></div>



    <div class="top-navbar-fixed">

        <nav class="sibling-website-nav">

            <ul>

                <li><a href="">Accounting</a></li><li class="active"><a href="">Training</a></li>

                <!-- <li><a href="">Recruitment</a></li> -->

            </ul>

        </nav>

The unnecessary whitespace makes it hard to work with. Fortunately, gulp has a plugin called HERE, which can help clean up the code like so:

var prettify = require('gulp-html-prettify');

gulp.task('templates', function() {
  gulp.src('./lib/*.html')
    .pipe(prettify({indent_char: ' ', indent_size: 2}))
    .pipe(gulp.dest('./dist/'))
});

While this works well, it creates new files in a different directory. What I aim for is to format the existing files in their current directories. How can I achieve this using gulp?

Answer №1

It seems like the solution is to make sure you use the pipe() function to direct your result to the correct directory. Here's a code snippet for reference:

var beautify = require('gulp-html-prettify');

gulp.task('templates', function() {
  gulp.src('./lib/*.html')
    .pipe(beautify({indent_char: ' ', indent_size: 2}))
    .pipe(gulp.dest('./lib/'))
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible for the UUIDs generated by the uuid package to be identical?

I am in need of creating unique UIDs for objects that will be stored in a database. To achieve this, I am utilizing the UUID npm package for generating unique identifiers. I have concerns regarding the possibility of duplicate IDs being generated by this p ...

Using webpack to bundle node_modules into your application

I am facing an issue while trying to load some modules like: moment echarts In my package.json file, I have the following versions specified: "echarts": "^3.1.10" "moment": "^2.14.1" However, I am encountering the errors below: VM2282:1 Uncaught Ref ...

Angular cookies may expire, but using the back button always revives them

Utilizing angular's cookie library, I have successfully set a cookie to store the id and passcode of a shopping cart on the backend. However, despite setting the expiration date to a past time in order to expire the cookie once the cart is purchased, ...

The dynamic loading of videos through the YouTube API

-Need to load multiple videos onto a page, keeping it simple -Each video has an ID stored in the database accessed via $slide['message'] -Currently only loading one video successfully, others show up as blank -Code is within a loop, attempt ...

What is the solution for handling undefined errors that occur when employing d3.select(this) within a Vue methods hook?

Currently, I am in the process of transferring d3 graphs from another project to my personal Vue-based project. Most aspects are functioning as expected, except for aligning labels in the arcs of a pie chart using the arc.centroid(d) method. Two errors kee ...

What is the best method for displaying a table using a JSON array?

I have a JSON array that I want to display in a table using React boxes: [ { id: 1, color: "red", size: "small" }, { id: 2, color: "blue", size: "medium" }, { id: 3, color: "green", size: "large" }, { id: 4, color: "yellow" ...

Reading a JSON file using Javascript (JQuery)

Struggling to figure out how to handle a JSON file using JavaScript. Here are the details : { "streetCity": { "132":"Abergement-Clemenciat", "133":"Abergement-de-Varey", "134":"Amareins" } } I am attempting to access ...

Slide your finger upwards to shut down the mobile navbar in bootstrap

Hey there, I'm currently developing a website using Bootstrap framework v3.3.4. I have a mobile navbar that opens when I click a toggle button, but I would like it to slide up to close the navigation instead. Here is an image showing the issue Do y ...

Display a close button for every individual item and use JavaScript to conceal the current item

I have a list that contains input fields along with delete link elements. I want to display the delete link element when the user hovers over the respective input field. Additionally, clicking on the close button (X) should hide the entire list item (li) f ...

Is there a specific measurement or scale for the dragging feature in jQuery UI draggables?

I'm interested in adjusting the position of my draggable element based on the distance moved by the mouse. For instance, if the scale is 1:2 and the cursor is moved 10px to the right, then the draggable should move 20px. I already have my draggable ...

The hyperlink activation event is malfunctioning

There seems to be an issue with the "Goods" link not working after clicking on "Shops." <div class="i_find"> <div class="replaced_link">Goods</div> <div class="link_container"><a href="#" class="a_shops">Shops</a&g ...

Issue with the useSWR hook causing the DOM not to update correctly due to mutation

My next.js app is utilizing the `useSWR` hook to fetch and populate data. const { data, error } = useSWR('/api/digest', fetcher, { revalidateOnFocus: false, }) The problem I am facing is that the DOM is not updating as expected after the `mu ...

Calculating the total of n natural numbers by utilizing a for loop

I have a question that involves calculating the sum of ten natural numbers, but for some reason the code provided is not working as expected. <!DOCTYPE html> <html> <head> <title>Sum of first 10 Natural numbers</title> & ...

Load pictures featuring a designated title

I have a collection of images stored in different categories: image-1-1.jpg image-2-2.jpg image-2-3.jpg image-2-4.jpg image-2-5.jpg image-3-1.jpg image-3-2.jpg image-3-3.jpg ... In addition, I also have links that correspond to each category: link 1 link ...

In my Node.js/Express.js application, I have a directory that holds various images. Whenever I attempt to view these images via their URL, I encounter a 404 error message

In my Node.js/Express js project, I have the following folder structure: root ----bin ----controllers ----middleware ----models ----node_modules ----public --------images ------------test.png ----routes ----views I am currently trying to determine the cor ...

Creating a Dynamic Bar in Your Shiny Application: A Step-by-Step Guide

Currently, I am developing a unique crowd funding shiny app to monitor donation amounts. Is there a method available that allows for the creation of a reactive bar in Shiny? Alternatively, is it feasible to achieve this using html, css, and javascript? He ...

The function Route.delete() expects a callback function, however, it received an [object Undefined] instead

Struggling with an error in my delete function that says "Route.delete() requires a callback function but got a [object Undefined]". Can't seem to figure out what's causing this issue. const playerController = { index: (request, response) ...

Encountering limitations in accessing certain object properties with the openweathermap API

As I integrate axios into my react application to retrieve weather data from the openweathermap api, I'm encountering some issues with accessing specific properties from the JSON object returned by the API call. For instance, I can easily access data. ...

Filtering incoming data from a Firestore database: A step-by-step guide

I'm facing a challenge while trying to incorporate this filtering mechanism into my code. FILTERING An issue arises when I attempt to implement the following lines of code: function search(text: string, pipe: PipeTransform): Country[] { return CO ...

Activate the feature of smooth shading using Three.js

When rendering an object with textures using MTL and OBJ files in Three.js, I encountered an issue where my model was displayed with flat shading. How can I enable smooth shading? var scene = new THREE.Scene(); var mtlLoader = new THREE.MTLLoader(); mtl ...