緣由猜測:使用html-loader
加載了兩次html
html
好比,錯誤示例:app
module: { rules: [ // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader' {test: /\.ts$/, loader: "ts-loader"}, {test: /\.(html)$/, loader: "html-loader"}, {test: /\.html/, loader: "html-loader"} ] },
則在代碼中看到require('./yunzhi.html')
時。首先,因爲符合第一條 {test: /\.(html)$/, loader: "html-loader"},
則將html
編譯爲變量A -> (module.exports)
;而後,因爲再次符合第二條規則{test: /\.html/, loader: "html-loader"}
,又從新將A進行了二次編譯,而後就出現了咱們不想看到的。ui
a.htmlspa
<yunzhi></yunzhi>
yunzhi組件code
app.component('yunzhi', { template: require('./yunzhi.html') ... });
yunzhi.htmlcomponent
<h1>hello</h1> <h2>hello</h2>
則發生以下錯誤:htm
刪除冗餘的loader
刪除前:ip
module: { rules: [ // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader' {test: /\.ts$/, loader: "ts-loader"}, {test: /\.(html)$/, loader: "html-loader"}, {test: /\.html/, loader: "html-loader"} ] },
刪除後:it
module: { rules: [ // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader' {test: /\.ts$/, loader: "ts-loader"}, {test: /\.(html)$/, loader: "html-loader"}, ] },