How to replace html tags and save to a new file

Asked

Viewed 38 times

1

I’m trying to check a file .html, remove some tags and create a new file with the changes made.

In the method that I am using at the moment (js, Gulp) I end up doing several Restplaces in chain, I believe that this is not the best way, I would like to know a better method of doing this.

Follow the code of my current task:

var gulp = require("gulp");
var fs = require("fs");

gulp.task("fixes", function(done) {
  var conteudo;

  fs.readFile("index.html", "utf-8", (err, data) => {
    if (err) throw err;
    conteudo = data;

    var t = data.replace(/(<body>|<\/body>)/g, "");
    var final = t.replace(/<meta charset="utf-8">/, "");

    fs.writeFile("dist.html", final, err => {
      if (err) throw err;
    });
  });

  console.log("Novo arquivo criado!");
  done();
});

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.