diff --git a/packages/web3/angular-patch.js b/packages/web3/angular-patch.js new file mode 100644 index 00000000000..3a76568e4cd --- /dev/null +++ b/packages/web3/angular-patch.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const f = '../../node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'; + +// This is because we have to replace the `node:false` in the `/angular-cli-files/models/webpack-configs/browser.js` +// with `node: {crypto: true, stream: true}` to allow web3 to work with angular (as they enforce node: false.) +// as explained here - https://github.com/ethereum/web3.js/issues/2260#issuecomment-458519127 +if (fs.existsSync(f)) { + fs.readFile(f, 'utf8', function(err, data) { + if (err) { + return console.log(err); + } + var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}'); + fs.writeFile(f, result, 'utf8', function(err) { + if (err) return console.log(err); + }); + }); +} diff --git a/packages/web3/package.json b/packages/web3/package.json index 59c75f0db7e..bdbe2e3520b 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -20,7 +20,8 @@ "author": "ethereum.org", "types": "types/index.d.ts", "scripts": { - "dtslint": "dtslint types --onlyTestTsNext" + "dtslint": "dtslint types --onlyTestTsNext", + "postinstall": "node angular-patch.js" }, "authors": [ {