File tree Expand file tree Collapse file tree 6 files changed +81
-38
lines changed
examples/vite-example/src Expand file tree Collapse file tree 6 files changed +81
-38
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -801,6 +801,8 @@ The callback is called when the packet has been removed.
801
801
Closes the Store.
802
802
803
803
<a name =" browser " ></a >
804
+ <a name =" webpack " ></a >
805
+ <a name =" vite " ></a >
804
806
805
807
## Browser
806
808
@@ -812,7 +814,15 @@ You can find all mqtt bundles versions in `dist` folder:
812
814
- ` mqtt.min.js ` - iife format, minified
813
815
- ` mqtt.esm.js ` - esm format minified
814
816
815
- In order to import them use one of the following:
817
+ Starting from MQTT.js > 5.2.0 you can import mqtt in your code like this:
818
+
819
+ ``` js
820
+ import mqtt from ' mqtt'
821
+ ```
822
+
823
+ This will be automatically handled by your bundler.
824
+
825
+ Otherwise you can choose to use a specific bundle like:
816
826
817
827
``` js
818
828
import * as mqtt from ' mqtt/dist/mqtt'
@@ -830,30 +840,6 @@ See <http://unpkg.com> for the full documentation on version ranges.
830
840
831
841
** Be sure to only use this bundle with ` ws ` or ` wss ` URLs in the browser. Others URL types will likey fail**
832
842
833
- <a name =" webpack " ></a >
834
-
835
- ### Webpack
836
-
837
- If you are using webpack simply import MQTT.js in one of the following ways:
838
-
839
- ``` js
840
- import * as mqtt from ' mqtt/dist/mqtt'
841
- import * as mqtt from ' mqtt/dist/mqtt.min'
842
- import mqtt from ' mqtt/dist/mqtt.esm'
843
- ```
844
-
845
- <a name =" vite " ></a >
846
-
847
- ### Vite
848
-
849
- If you are using vite simply import MQTT.js like this:
850
-
851
- ``` js
852
- import * as mqtt from ' mqtt/dist/mqtt'
853
- import * as mqtt from ' mqtt/dist/mqtt.min'
854
- import mqtt from ' mqtt/dist/mqtt.esm'
855
- ```
856
-
857
843
<a name =" qos " ></a >
858
844
859
845
## About QoS
Original file line number Diff line number Diff line change 1
1
<script setup>
2
2
import { ref } from ' vue'
3
- import { connect } from ' mqtt/dist/mqtt.min'
3
+ import mqtt from ' mqtt'
4
+
5
+ console .log (' mqtt' , mqtt)
4
6
5
7
const connected = ref (false )
6
8
7
- const client = connect (' wss://test.mosquitto.org:8081' );
9
+ const client = mqtt . connect (' wss://test.mosquitto.org:8081' );
8
10
9
11
const messages = ref ([])
10
12
Original file line number Diff line number Diff line change 21
21
"url" : " git://github.com/mqttjs/MQTT.js.git"
22
22
},
23
23
"main" : " ./build/mqtt.js" ,
24
+ "module" : " ./dist/mqtt.esm.js" ,
24
25
"bin" : {
25
26
"mqtt_pub" : " ./build/bin/pub.js" ,
26
27
"mqtt_sub" : " ./build/bin/sub.js" ,
35
36
" src/"
36
37
],
37
38
"exports" : {
38
- "." : " ./build/mqtt.js" ,
39
+ "." : {
40
+ "browser" : {
41
+ "import" : " ./dist/mqtt.esm.js" ,
42
+ "default" : " ./dist/mqtt.js"
43
+ },
44
+ "default" : " ./build/mqtt.js"
45
+ },
39
46
"./package.json" : " ./package.json" ,
40
47
"./*.map" : " ./build/*.js.map" ,
41
48
"./dist/*" : " ./dist/*.js" ,
95
102
"node" : " >=16.0.0"
96
103
},
97
104
"browser" : {
98
- "./mqtt.js" : " ./build /mqtt.js" ,
105
+ "./mqtt.js" : " ./dist /mqtt.js" ,
99
106
"fs" : false ,
100
107
"tls" : false ,
101
108
"net" : false
110
117
"help-me" : " ^4.2.0" ,
111
118
"lru-cache" : " ^10.0.1" ,
112
119
"minimist" : " ^1.2.8" ,
120
+ "mqtt" : " ^5.2.0" ,
113
121
"mqtt-packet" : " ^9.0.0" ,
114
122
"number-allocator" : " ^1.0.14" ,
115
123
"readable-stream" : " ^4.4.2" ,
Original file line number Diff line number Diff line change 1
1
import { expect } from '@esm-bundle/chai' ;
2
- import mqtt from '../../dist/mqtt.esm.js' ;
2
+ import mqtt from '../../' ; // this will resolve to mqtt/ dist/mqtt.esm.js
3
3
4
4
// needed to test no-esm version /dist/mqtt.js
5
5
/** @type { import('../../src/mqtt').MqttClient }*/
You can’t perform that action at this time.
0 commit comments