ฉันต้องการเป็น Gulp องงานที่จะต้องผ่านทุกกำหนดเอกสาร HTML และลบบางแอททริบิวต์ต่างๆ(เช่นรูปแบบ=""). ฉันคิดว่าฉันอาจจะสามารถที่จะทำแบบเดียวกับที่ฉันทำมันผ่านเบราว์เซอร์,แต่ดูเหมือนว่าไม่. นี่คือสิ่งที่ฉันกำลังพยายามทำอย่าง:
// function to take multiple attributes from an element
const discardAttributes = (element, ...attributes) =>
attributes.forEach((attribute) => element.removeAttribute(attribute));
// run the function on multiple elements
document.querySelectorAll("table, thead, tbody, tr, th, td").forEach((elem) => {
discardAttributes(elem, "cellspacing", "cellpadding", "width", "style");
});
ฉันต้องไปแล้วเอาไปอยู่เหนือสูตรและสร้างสัมดแก้วงานเหมือนแล้ว:
const gulp = require("gulp");
gulp.task("clean", async () => {
gulp.src("src/*.html")
.pipe(discardAttributes())
.pipe(gulp.dest("dist"));
});
ถ้ามันมีปลั๊กออก-ในฉันสามารถใช้มันจะทำอย่างนี้ได้โปรดแบ่งปันแต่ก็ฉันอยากจะเรียนรู้ที่จะทำมันด้วยตนเองแบบนี้
ฉันต้องใช้ through2?
ขอบคุณ