gpt4 book ai didi

angular - 如何在 rollup 中导入 stompjs

转载 作者:太空狗 更新时间:2023-10-29 17:38:24 25 4
gpt4 key购买 nike

在带有 typescript 的 ng2 应用程序上,我使用的是 stompjs,它在没有汇总的情况下工作正常。

我正在导入它:

从“stompjs”导入 {Stomp}

运行 rollup 后我得到“异常:Stomp 未定义”

我的汇总配置是:

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' ]
}
})
]
}

stompjs 的 TypeScript 类型定义文件

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;
}

最佳答案

使用 import * as Stomp from "stompjs"

关于angular - 如何在 rollup 中导入 stompjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40114618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com