【发布时间】:2017-08-15 08:28:44
【问题描述】:
我正在尝试从外部文件加载我的淘汰赛模板。
我的设置如下:
- npm
- 网页包
- 打字稿
现在,我尝试了几个不同的选项,但都没有奏效:
text-loader / raw-loader / html-loader
template: require("text-loader!./my-component.html")
// or
template: require("raw-loader!./my-component.html")
// or
template: require("html-loader!./my-component.html")
不起作用,因为这会返回一个类似于 Javascript 代码的文本,其中包含我的模板。
knockout-template-loader
template: require("knockout-template-loader!html-loader!./my-component.html")
不起作用,因为它只返回一个空对象。
script-template-loader
template: require("script-template-loader?addToDom=true!./hello.html")
这有两个问题:
- 模板不喜欢 HTMLScriptElement 对象
- 生成的脚本在字符串
[object Object]旁边没有实际内容
require 选项
template: {require: "text-loader!./my-component.html"}
没有工作,因为我在运行时遇到错误:
无法读取
__webpack_require__处未定义的属性“调用”
我错过了什么?
【问题讨论】:
标签: typescript knockout.js webpack webpack-2