Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cameronelliott/5406cdbe62877261c338e3e06a6f0af2 to your computer and use it in GitHub Desktop.
Save cameronelliott/5406cdbe62877261c338e3e06a6f0af2 to your computer and use it in GitHub Desktop.
This gist explains one way to create a JS browser bundle for async-mqtt

How-to on bundling async-mqtt for the browser

mkdir foo
cd foo
npm install async-mqtt
npm install browserify
npm install tinyify
cd node_modules/async-mqtt/
npm install .
npx browserify index.js -p tinyify -s AsyncMqtt >browserAsyncMqtt.js

Show the compressed size to understand likley HTTP transfer size.

gzip <browserAsyncMqtt.js | wc -c

Be sure to only use this bundle with ws or wss URLs in the browser. Others will likey fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment