目標(biāo)文件: html-webpack-plugin/index.js
/**
* Injects the assets into the given html string
*/
HtmlWebpackPlugin.prototype.injectAssetsIntoHtml=function(html,assets,assetTags) {
varhtmlRegExp =/(]*>)/i;
varheadRegExp =/(<\/head>)/i;
varbodyRegExp =/(<\/body>)/i;
varcssRegExp =/()/i;
varscriptRegExp =/()/i;
varbody = assetTags.body.map(this.createHtmlTag);
varhead = assetTags.head.map(this.createHtmlTag);
varself =this;
if(self.options.inject ==="tpltag"){
if(cssRegExp.test(html)){
headRegExp = cssRegExp;
}
if(scriptRegExp.test(html)){
bodyRegExp = scriptRegExp;
}
}
if(body.length) {
if(bodyRegExp.test(html)) {
// Append assets to body element
html = html.replace(bodyRegExp,function(match) {
if(self.options.inject ==="tpltag") match =''
returnbody.join('') + match;
});
}else{
// Append scripts to the end of the file if no element exists:
html += body.join('');
}
}
if(head.length) {
// Create a head tag if none exists
if(!headRegExp.test(html)) {
if(!htmlRegExp.test(html)) {
html =''+ html;
}else{
html = html.replace(htmlRegExp,function(match) {
returnmatch +'';
});
}
}
// Append assets to head element
html = html.replace(headRegExp,function(match) {
if(self.options.inject ==="tpltag") match =''
returnhead.join('') + match;
});
}
// Inject manifest into the opening html tag
if(assets.manifest) {
html = html.replace(/(]*)(>)/i,function(match,start,end) {
// Append the manifest only if no manifest was specified
if(/\smanifest\s*=/.test(match)) {
returnmatch;
}
returnstart +' manifest="'+ assets.manifest+'"'+ end;
});
}
returnhtml;
};
使用 webpack配置
varconf = {
filename: '',//編譯后生成的jinja存放路徑,相對(duì)于path
template:'',//html模板路徑
inject:'tpltag',//js插入的位置,true/'head'/'body'/false
hash:false,
minify:false,
chunks: []
};
return newHtmlWebpackPlugin(conf);
模板實(shí)例
{%extends"base.jinja"%}
{%blocktitle%}音樂(lè)上傳-婚禮時(shí)光{%endblock%}
{%blockkeywords%}婚禮,婚禮布置,電子請(qǐng)柬,主題婚禮,婚禮圖片,婚禮靈感{%endblock%}
{%blockdescription%}婚禮時(shí)光是一站式婚禮創(chuàng)意平臺(tái)简烘,可以尋找婚禮靈感夸研,主題婚禮案例亥至,免費(fèi)定制電子請(qǐng)柬姐扮,預(yù)約婚禮服務(wù)茶敏,分享幸福時(shí)光{%endblock%}
{%blocksub_css%}
{%endblock%}
{%blockmain%}
{%endblock%}
{%blockfooter%}
{%endblock%}
{%blockscript%}
{%endblock%}
編譯完后的代碼
{%extends"v4/base.jinja"%}
{%blocktitle%}音樂(lè)上傳-婚禮時(shí)光{%endblock%}
{%blockkeywords%}婚禮,婚禮布置,電子請(qǐng)柬,主題婚禮,婚禮圖片,婚禮靈感{%endblock%}
{%blocksub_css%}
{%endblock%}
{%blockmain%}
{%endblock%}
{%blockfooter%}
{%endblock%}
{%blockscript%}
{%endblock%}
** 簡(jiǎn)書(shū)怎么代碼粘貼進(jìn)去被過(guò)濾掉了 **