缘由猜测:使用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"}, ] },