diff --git a/esbuild.js b/esbuild.js index 019418a5f..68a04bb9f 100644 --- a/esbuild.js +++ b/esbuild.js @@ -79,6 +79,7 @@ async function run() { options.outfile = `${outdir}/mqtt.esm.js` options.format = 'esm' + options.entryPoints = ['build/index.esm.js'] await build(options) diff --git a/src/index.esm.ts b/src/index.esm.ts new file mode 100644 index 000000000..4574441e4 --- /dev/null +++ b/src/index.esm.ts @@ -0,0 +1,20 @@ +// ESM entry point for browser bundle +// This file explicitly re-exports using ES6 syntax to ensure +// esbuild properly creates named exports in the ESM bundle + +import * as mqtt from './mqtt' + +export default mqtt +export { + connect, + connectAsync, + MqttClient, + Client, + Store, + DefaultMessageIdProvider, + UniqueMessageIdProvider, + KeepaliveManager, +} from './mqtt' + +// Re-export all other exports +export * from './mqtt' diff --git a/src/index.ts b/src/index.ts index 22f29ba81..2480299d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,3 +2,15 @@ import * as mqtt from './mqtt' export default mqtt export * from './mqtt' + +// Explicit re-exports for ESM bundle compatibility +export { + connect, + connectAsync, + MqttClient, + Client, + Store, + DefaultMessageIdProvider, + UniqueMessageIdProvider, + KeepaliveManager, +} from './mqtt'