2016-10-18 24 views
5

Trên ứng dụng ng2 với typescript tôi đang sử dụng stompjs, và nó hoạt động tốt mà không có rollup.Làm thế nào để nhập khẩu stompjs trong rollup

tôi nhập khẩu nó:

import {Stomp} from "stompjs"

Sau khi chạy rollup tôi nhận được "EXCEPTION: Stomp không được định nghĩa"

rollup cấu hình của tôi là:

import rollup from 'rollup'; 
import nodeResolve from 'rollup-plugin-node-resolve'; 
import commonjs from 'rollup-plugin-commonjs'; 


export default { 
entry: 'aot/app/src/boot-aot.js', 
dest: 'dist/bundle.es2015.js', // output a single application bundle 
sourceMap: true, 
useStrict: false, 
format: 'iife', 
treeshake: true, 
plugins: [ 
    nodeResolve({ 
    module: true, 
    jsnext: true, 
    main: true, 
    browser: true, 
    extensions: ['.js'] 
    }), 
    commonjs({ 
    include: [ 
     'node_modules/rxjs/**', 
     'node_modules/stompjs/**' 
    ], 
    namedExports: { 
     'node_modules/stompjs/lib/stomp.min.js': [ 'Stomp' ] 
    } 
    }) 
] 
} 

định nghĩa kiểu đánh máy tệp cho stompjs

declare module "stompjs" { 

    export interface Client { 
    heartbeat: any; 

    debug(...args: string[]); 

    connect(...args: any[]); 
    disconnect(disconnectCallback:() => any, headers?: any); 

    send(destination: string, headers?:any, body?: string); 
    subscribe(destination: string, callback?: (message: Message) => any, body?: string); 
    unsubscribe(); 

    begin(transaction: string); 
    commit(transaction: string); 
    abort(transaction: string); 

    ack(messageID: string, subscription: string, headers?: any); 
    nack(messageID: string, subscription: string, headers?: any); 
    } 

    export interface Message { 
    command: string; 
    headers: any; 
    body: string; 

    ack(headers?: any); 
    nack(headers?: any); 
    } 

    export interface Frame { 
    constructor(command: string, headers?: any, body?: string); 

    toString(): string; 
    sizeOfUTF8(s: string); 
    unmarshall(datas: any); 
    marshall(command: string, headers?, body?); 
    } 

    export interface Stomp { 
    client: Client; 
    Frame: Frame; 

    over(ws: WebSocket); 
    } 

    export default Stomp; 
} 

Trả lời

1

Sử dụng import * as Stomp from "stompjs"

Các vấn đề liên quan