當前位置:吉日网官网 - 盛世收藏 - grunt如何合並html

grunt如何合並html

簡單的方法是提取頁眉和頁腳,通過占位符在html中引入它們,然後編寫壹個自定義任務來插入。

比如header.html的路徑是:/common/header.html,妳的某個頁面可能會引入這樣的頭文件:

& lt!DOCTYPE html & gt

& lthtml & gt

& lthead & gt

& lttitle & gtA & lt/title & gt;

& lt/head & gt;

& ltbody & gt

& ltinclude src = "/common/header . html "/& gt;

& lt/body & gt;

& lt/html & gt;

然後編寫壹個簡單的任務來打包html文件,並將

grunt.registerTask('htmlpack ',function(){

var dir = xxxx//源文件的路徑

var destDir = xxxx//要保存的路徑

//讀取源文件

fs.readDir(目錄,函數(文件名){

var file = fs.readFile(文件名);

var include = file . match(/\ & lt;包括。+?\/\ & gt;/);

//替換內容

include.forEach(函數(項){

var src = item . replace(' & lt;包括src= " " ',' ')。替換(“/>;', '');

var html = fs . readfile(src);

file.replace(item,html);

});

//輸出文件

fs.writeFile(destDir+filename,file);

})

})

  • 上一篇:哪個高清壓制小組出的片質量最高最穩定最適合收藏?
  • 下一篇:k2手鏈有收藏價值嗎?
  • copyright 2024吉日网官网