Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. gulp.task("templates", () =>
  2.     gulp.src("src/components/*.html")
  3.         .pipe(insert.transform((content, file) => {
  4.             const componentName = path.basename(file.path, ".html");
  5.             const document = (new JSDOM(content)).window.document;
  6.             const templatesTags = document.querySelectorAll("template");
  7.             templatesTags.forEach(template => template.setAttribute("data-component", componentName));
  8.             const templatesHTML = Array.prototype.map.call(templatesTags, tag => tag.outerHTML);
  9.             return templatesHTML.join("");
  10.         }))
  11.         .pipe(concat("templates.html"))
  12.         .pipe(gulp.dest("dist"))
  13. );
  14.  
  15. gulp.task("html", () =>
  16.     gulp.src("src/index.html")
  17.         .pipe(replace("@@templates", () => fs.readFileSync("./dist/templates.html")))
  18.         .pipe(gulp.dest("dist"))
  19. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement