I'm using angular2 and webpack2 in my project.
My co-workers start the project from Angular2 QuickStart, and then I move it to Webpack environment.
I use html-loader to load components templats and use url-loader to extract images and fonts:
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
use: 'url-loader?limit=1000&name=assets/[name].[hash].[ext]'
},
The templates are like this:
<section class="creation-mobile">
<img src="../../../images/camera/cn/mobile/creation.jpg" alt="" class="img-cn">
<img src="../../../images/camera/en/mobile/creation.jpg" alt="" class="img-en">
</section>
When I build it, Webpack can find the images and export them into asstes/.
It works fine until I meet templates like this:
<li *ngFor="let i of [1,2,3]" class="item{{i}} m1-view">
<div class="{{lang}}-video-view">
<img src="../../../images/os/{{lang}}/medium/one-step{{i}}{{deviceRatio == 1?'':'@2x'}}.jpg">
<video class="video-medium" preload="auto" src="../../../videos/os/{{lang}}/medium/one-step-{{i}}{{deviceRatio == 1?'':'@2x'}}.mp4" [video-play]="onestepVideoState[i-1]"></video>
<img src="../../../images/os/{{lang}}/large/one-step{{i}}{{deviceRatio == 1?'':'@2x'}}.jpg">
<video class="video-large" preload="auto" src="../../../videos/os/{{lang}}/large/one-step-{{i}}{{deviceRatio == 1?'':'@2x'}}.mp4" [video-play]="onestepVideoState[i-1]"></video>
</div>
<a class="replay" [innerHTML]="os.replay.title" [ngClass]="{'active': onestepReplayState[i-1]}" (click)="onestepReplay(i-1)"></a>
</li>
The src like ../../../images/os/{{lang}}/medium/one-step{{i}}{{deviceRatio == 1?'':'@2x'}}.jpg contains {{lang}} and {{i}} and {{deviceRatio == 1?'':'@2x'}} to fetch different resources, and url-loader can not resolve this kind of url.
We have to spread out *ngFor and use ngif, write plenty of <img> tag to import images.
Are there some ways to load this kind of urls in angular2 and webpack?
Add1: sorry to forget to declare, lang and deviceRatio are depend on the browser environment, so the value is not sure when build. the value of lang would be one of cn and en, so we want to load both ../../../images/os/en/medium/..xxx.jpg and ../../../images/os/cn/medium/..xxx.jpg to the final dist directory.