Skip to content

Commit

Permalink
feat: remove 3 http related polyfills (#2375)
Browse files Browse the repository at this point in the history
Switch to using fetch for browser and `node-fetch` for node for the faucet calls.  This reduces the webpack bundle by 3.2% or 16.5kb gzipped.

The fundWallet code has been refactored to be much more straight forward due to not having to do such low level operations.

This improves the frontend setup process by no longer requiring several polyfills such as `url`, `stream-http`, and `https-browserify`.
  • Loading branch information
ckniffen committed Sep 1, 2023
1 parent 7fa7dc6 commit 921c56c
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 202 deletions.
15 changes: 1 addition & 14 deletions UNIQUE_SETUPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ To use `xrpl.js` with React, you need to install shims for core NodeJS modules.
assert \
buffer \
crypto-browserify \
https-browserify \
os-browserify \
process \
stream-browserify \
stream-http \
url
stream-browserify
```

2. Modify your webpack configuration
Expand All @@ -48,11 +44,7 @@ To use `xrpl.js` with React, you need to install shims for core NodeJS modules.
Object.assign(fallback, {
assert: require.resolve("assert"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify"),
stream: require.resolve("stream-browserify"),
url: require.resolve("url"),
ws: require.resolve("xrpl/dist/npm/client/WSWrapper"),
});
config.resolve.fallback = fallback;
Expand Down Expand Up @@ -141,7 +133,6 @@ export default defineConfig({
},
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
Expand All @@ -165,8 +156,6 @@ resolve: {
events: 'events',
crypto: 'crypto-browserify',
stream: 'stream-browserify',
http: 'stream-http',
https: 'https-browserify',
ws: 'xrpl/dist/npm/client/WSWrapper',
},
}})
Expand All @@ -181,8 +170,6 @@ npm install --save-dev @esbuild-plugins/node-globals-polyfill \
events \
crypto-browserify \
stream-browserify \
stream-http \
https-browserify \
xrpl
```
Expand Down
76 changes: 53 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"eslint-plugin-tsdoc": "^0.2.16",
"eventemitter2": "^6.0.0",
"expect": "^29.3.1",
"https-browserify": "^1.0.0",
"jest": "^29.3.1",
"jest-mock": "^29.3.1",
"lerna": "^4.0.0",
Expand All @@ -60,12 +59,10 @@
"source-map-loader": "^4.0.1",
"source-map-support": "^0.5.16",
"stream-browserify": "^3.0.0",
"stream-http": "3.2.0",
"ts-jest": "^29.0.3",
"ts-loader": "^9.2.5",
"ts-node": "^10.2.1",
"typescript": "^5.1.6",
"url": "^0.11.0",
"webpack": "^5.81.0",
"webpack-bundle-analyzer": "^4.1.0",
"webpack-cli": "^5.0.1"
Expand Down
1 change: 1 addition & 0 deletions packages/xrpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"bignumber.js": "^9.0.0",
"bip32": "^2.0.6",
"bip39": "^3.0.4",
"cross-fetch": "^4.0.0",
"ripple-address-codec": "^4.3.0",
"ripple-binary-codec": "^1.9.0",
"ripple-keypairs": "^1.3.0",
Expand Down
Loading

0 comments on commit 921c56c

Please sign in to comment.