File tree 3 files changed +26
-4
lines changed
3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,6 @@ const options = {
16
16
format : 'iife' ,
17
17
platform : 'browser' ,
18
18
globalName : 'mqtt' ,
19
- define : {
20
- 'process.env.npm_package_version' : JSON . stringify ( version ) ,
21
- } ,
22
19
sourcemap : false , // this can be enabled while debugging, if we decide to keep this enabled we should also ship the `src` folder to npm
23
20
plugins : [
24
21
polyfillNode ( {
@@ -34,6 +31,27 @@ const options = {
34
31
navigator : true , // Needed for WeChat, ref #1789
35
32
}
36
33
} ) ,
34
+ {
35
+ name : 'resolve-package-json' ,
36
+ setup ( build ) {
37
+ // when importing 'package.json' we want to provide a custom object like { version: '1.2.3' }
38
+
39
+ build . onResolve ( { filter : / p a c k a g e \. j s o n $ / } , args => {
40
+ return {
41
+ path : args . path ,
42
+ namespace : 'package-json'
43
+ }
44
+ } )
45
+
46
+ build . onLoad ( { filter : / .* / , namespace : 'package-json' } , args => {
47
+ return {
48
+ contents : JSON . stringify ( { version } ) ,
49
+ loader : 'json'
50
+ }
51
+ }
52
+ )
53
+ }
54
+ } ,
37
55
] ,
38
56
}
39
57
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import {
31
31
ErrorWithReasonCode ,
32
32
GenericCallback ,
33
33
IStream ,
34
+ MQTTJS_VERSION ,
34
35
StreamBuilder ,
35
36
TimerVariant ,
36
37
VoidCallback ,
@@ -396,7 +397,7 @@ export interface MqttClientEventCallbacks {
396
397
* (see Connection#connect)
397
398
*/
398
399
export default class MqttClient extends TypedEventEmitter < MqttClientEventCallbacks > {
399
- public static VERSION = process . env . npm_package_version
400
+ public static VERSION = MQTTJS_VERSION
400
401
401
402
/** Public fields */
402
403
Original file line number Diff line number Diff line change @@ -82,3 +82,6 @@ export const nextTick =
82
82
: ( callback : ( ) => void ) => {
83
83
setTimeout ( callback , 0 )
84
84
}
85
+
86
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
87
+ export const MQTTJS_VERSION = require ( '../../package.json' ) . version
You can’t perform that action at this time.
0 commit comments