How to replace html tags and save to a new file

1

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

In the method I am currently using (js, gulp) I end up doing multiple replaces in jail, I believe this is not the best way, I would like to know a better method to do this.

Here is the code for 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();
});
    
asked by anonymous 02.05.2018 / 14:56

0 answers