I am trying to load my knockout templates from external files.
My setup is as follows:
Now, I have tried a few different options but none worked:
template: require("text-loader!./my-component.html")
// or
template: require("raw-loader!./my-component.html")
// or
template: require("html-loader!./my-component.html")
Didn't work as this returns a text that resembles Javascript code with my template somewhere inside.
template: require("knockout-template-loader!html-loader!./my-component.html")
Didn't work as it just returns an empty object.
template: require("script-template-loader?addToDom=true!./hello.html")
This has two problems:
[object Object]
require
optiontemplate: {require: "text-loader!./my-component.html"}
Didn't work as I am getting an error at runtime:
Cannot read property 'call' of undefined at
__webpack_require__
What am I missing?
The html-loader plugin is indeed working. Why it wasn't working at first was that I registered knockout-template-loader
in my webpack.config.js as the default loader for html files.
Looks like it is using that even if a specific loader is specified in the require.
After removing that rule, it works now