1
我正在做我的第一個Angular 2庫。目前,這只是一個組件庫。我想要一個兼容Webpack和SystemJS的庫。我設法編寫了一個與SystemJs兼容的代碼的第一個組件,並將代碼重寫爲與Webpack兼容,但是哪個是正確的代碼來強制它與兩者兼容?如何創建一個與webpack.js和system.js兼容的Angular 2組件庫?
import {Component} from '@angular/core';
@Component({
selector: 'foo',
moduleId: typeof module.id == "string" ? module.id : null,
templateUrl: 'foo.component.html',
styleUrls: ['foo.component.css']
})
export class FooComponent {
logo: String;
name: String;
constructor() {
this.logo = '';
this.name = 'My name';
}
}
目前我發現this trick解決了相對路徑問題的一部分。該工程與systemJS但我還是這個錯誤使用的WebPack項目:
Cannot GET /application.component.html
Unhandled Promise rejection: Failed to load foo.component.html ; Zone: <root> ; Task: Promise.then ; Value: Failed to load foo.component.html undefined
Error: Uncaught (in promise): Failed to load foo.component.html