我正在尝试从外部文件加载我的淘汰模板 我的设置如下:
现在,我尝试了一些不同的选择但没有效果:
template: require("text-loader!./my-component.html")
// or
template: require("raw-loader!./my-component.html")
// or
template: require("html-loader!./my-component.html")
没有工作,因为这会返回一个类似Javascript代码的文本,里面有我的模板。
template: require("knockout-template-loader!html-loader!./my-component.html")
没有工作因为它只返回一个空对象。
template: require("script-template-loader?addToDom=true!./hello.html")
这有两个问题:
[object Object]
require
选项template: {require: "text-loader!./my-component.html"}
我没有工作,因为我在运行时收到错误:
无法阅读财产'来电'未定义
__webpack_require__
我缺少什么?
答案 0 :(得分:2)
html-loader插件确实有效。为什么它最初没有工作的是我在webpack.config.js中注册了knockout-template-loader
作为html文件的默认加载器。
即使在require中指定了特定的加载器,它看起来也在使用它
删除该规则后,它现在可以使用