My objective is to import my HTML template in a way that webpack can recognize and include them during the build process. (webpack -d)
As advised in this GitHub thread, I should follow these steps:
declare module '*.html' {
const _: string;
export default _;
}
Afterwards, importing the template using
import template from './myTemplate.html';
should be successful.
Unfortunately, it doesn't seem to work as expected.
import template from './myTemplate.html';
console.log(template); // undefined
Strangely enough, this approach seems to "work":
import * as template from './myTemplate.html';
console.log(template); // <p>Hello world!</p>
However, the following method fails:
$routeProvider.when("/test", {
template: template, // ERROR! template is typeof(*.html) expected string
controller: MyController,
controllerAs: "$ctrl"
});
If I modify my *.html module to resemble this:
declare module '*.html' {
const _: string;
export = _; // changed this
}
I can then proceed with:
import * as template from './myTemplate.html';
$routeProvider.when("/test", {
template: template, // Great success!
controller: MyController,
controllerAs: "$ctrl"
});
It does the job, but why doesn't
import template from './myTemplate.html';
behave as expected? What am I missing, since others on the GitHub thread seemed to have success with that method.