我想用webpack awesome-typescript-loader來捆綁我的項目,但是我遇到了一些模塊不能自行導出的問題。如何導入不使用awesome-typescript-loader導出模塊的npm包?
一個例子是bootstrap-dialog npm軟件包(我安裝了bootstrap-switch和@ types/bootstrap-switch軟件包)。 @types不會導出模塊,只是聲明一個名稱空間,並添加到JQuery接口中。 :https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/bootstrap-switch/index.d.ts
在我app.ts我用它作爲這樣的:
import {OtherClass} from './otherclass'
$(document).ready(()=>{
let thisPage= new PageEntry();
thisPage.init();
}
class PageEntry {
public init(): void {
$('.bss').bootstrapSwitch();
let x = new OtherClass();
x.doSomething();
}
}
但是從的WebPack輸出不包括bootstrapSwitch代碼。我嘗試添加: import * as BootstrapSwitch from 'bootstrap-switch';
但我顯然得到一個錯誤,指出
node_modules/@types/bootstrap-switch/index.d.ts'不是一個模塊。
如何確保引導開關被拉入?
我使用bootstrap-switch作爲例子,但是我有大約5個包含相同問題的包。
我已經能夠得到這個與以下工作: – sheamus