Skip to content

Commit 25c8ca4

Browse files
Oleksii Zaichkosclausen
authored andcommitted
refactor: refactor script and update README.md
1 parent b488b80 commit 25c8ca4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ Those commands will autoupdate changelog and dependant package.json's
2020

2121
Unfortunately command `npm publish` is broken due to nature of ng-packager.
2222
It's substituted with `npm run publish`, which will correctly build and publish production build
23+
24+
## Webpack shimming
25+
26+
ngx-mqtt depends on mqtt package which uses node globals.
27+
In order to make it run inside browser it includes a postinstall script which patches Angular webpack config of the project it was imported into.
28+
To disable this, you have to set `mqtt-disable-hook` environmental variable while installing this package.
29+

projects/ngx-mqtt/postinstall.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
if (process.env['mqtt-disable-hook']) {
2+
return 0;
3+
}
4+
15
const fs = require('fs');
26
const f = '../../node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
37

48
fs.readFile(f, 'utf8', function (err,data) {
59
if (err) {
6-
return console.log(err);
10+
console.error(err);
11+
throw err;
712
}
813
// at some moment angular-cli tam disabled node polyfills and stubs in webpack
914
// from:
@@ -12,6 +17,9 @@ fs.readFile(f, 'utf8', function (err,data) {
1217
// node: {global: true}
1318
const result = (data.replace(/node: false/g, "node: {global: true}"));
1419
fs.writeFile(f, result, 'utf8', function (err) {
15-
if (err) return console.log(err);
20+
if (err) {
21+
console.error(err);
22+
throw err;
23+
}
1624
});
1725
});

0 commit comments

Comments
 (0)