I'm writing a simple Angular2 component:
@Component({ ...,
template: `
<img id="logo" src="../img/logo.png">
`, ...
})
I'm using a webpack config very similar to the official docs so the .component.ts file is being passed through awesome-typescript-loader. When I build the project, this component winds up with <img id="logo" src="../img/logo.png"> in the page, i.e. the image URL isn't rewritten by Webpack. I believe this is because inline templates aren't being parsed for src properties.
I have tried working around this by doing an explicit require():
const SITE_LOGO = require("../img/logo.png");
@Component({ ...,
template: `
<img id="logo" [src]="logo">
`, ...
})
export class AppComponent {
logo = SITE_LOGO;
}
This seems like a lot of extra work, but it does get the job done -- the image winds up with src="data:image/png;base64...".
It'd be nice to have sources fixed up automatically, but there's a bigger issue: when Webpack doesn't do the parsing, the assignment goes through Angular's DOM sanitizer and SVG images get prefixed with unsafe: which means they don't get rendered in the browser. I see a workaround that involves de-sanitizing the string but it kind of seems like a hack. I'd avoid all this if I could get Webpack to just rewrite my inline template for me.