mirror of
				https://github.com/Xahau/xahau.js.git
				synced 2025-11-04 04:55:48 +00:00 
			
		
		
		
	feat: isomorphic sockets and use eventemitter3 (#2514)
Reduces filesize by 3kb minified and gzipped or 2.8% and reduces bundler
config steps.
- Move `WSWrapper` to `@xrpl/isomorphic` to remove the need to add
mapping of `ws` to `WSWrapper` file in bundler configs
- Switch to `eventemitter3` which is smaller than `events` by almost
1kb and will not require a mapping to node's `events` in `vite`
bundling. `webpack` always automatically maps it.
    - max listeners is not a thing for `eventemitter3` so we do not
need to set it to `Infinity`. `ws` uses the native event emitter which
does still need that to be set.
- Remove `eventemitter2` which was only used in tests and was replaced
with `eventemitter3`
BREAKING CHANGE: Config for frontend bundlers has changed for `ws`.
			
			
This commit is contained in:
		@@ -37,11 +37,6 @@ To use `xrpl.js` with React, you need to install shims for core NodeJS modules.
 | 
			
		||||
      const webpack = require("webpack");
 | 
			
		||||
 | 
			
		||||
      module.exports = function override(config) {
 | 
			
		||||
        const fallback = config.resolve.fallback || {};
 | 
			
		||||
        Object.assign(fallback, {
 | 
			
		||||
          ws: require.resolve("xrpl/dist/npm/client/WSWrapper"),
 | 
			
		||||
        });
 | 
			
		||||
        config.resolve.fallback = fallback;
 | 
			
		||||
        config.plugins = (config.plugins || []).concat([
 | 
			
		||||
          new webpack.ProvidePlugin({
 | 
			
		||||
            process: "process/browser",
 | 
			
		||||
@@ -127,30 +122,25 @@ export default defineConfig({
 | 
			
		||||
  },
 | 
			
		||||
  optimizeDeps: {
 | 
			
		||||
    esbuildOptions: {
 | 
			
		||||
        define: {
 | 
			
		||||
          global: 'globalThis',
 | 
			
		||||
        },
 | 
			
		||||
        plugins: [
 | 
			
		||||
            NodeGlobalsPolyfillPlugin({
 | 
			
		||||
                process: true,
 | 
			
		||||
                buffer: true,
 | 
			
		||||
            }),
 | 
			
		||||
        ],
 | 
			
		||||
    },
 | 
			
		||||
},
 | 
			
		||||
build: {
 | 
			
		||||
  rollupOptions: {
 | 
			
		||||
      define: {
 | 
			
		||||
       global: 'globalThis',
 | 
			
		||||
      },
 | 
			
		||||
      plugins: [
 | 
			
		||||
          polyfillNode(),
 | 
			
		||||
        NodeGlobalsPolyfillPlugin({ 
 | 
			
		||||
          process: true, 
 | 
			
		||||
          buffer: true, 
 | 
			
		||||
        }),
 | 
			
		||||
      ],
 | 
			
		||||
    },
 | 
			
		||||
  }, 
 | 
			
		||||
  build: { 
 | 
			
		||||
    rollupOptions: {
 | 
			
		||||
      plugins: [
 | 
			
		||||
        polyfillNode(),
 | 
			
		||||
      ]
 | 
			
		||||
  }
 | 
			
		||||
},
 | 
			
		||||
resolve: {
 | 
			
		||||
  alias: {
 | 
			
		||||
    events: 'events',
 | 
			
		||||
    ws: 'xrpl/dist/npm/client/WSWrapper',
 | 
			
		||||
    } 
 | 
			
		||||
  },
 | 
			
		||||
}})
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
3. Install the config dependencies and xrpl (e.g. using this command)
 | 
			
		||||
@@ -158,9 +148,7 @@ resolve: {
 | 
			
		||||
```shell
 | 
			
		||||
npm install --save-dev @esbuild-plugins/node-globals-polyfill \
 | 
			
		||||
		rollup-plugin-polyfill-node \
 | 
			
		||||
		&& npm install
 | 
			
		||||
		events \
 | 
			
		||||
		xrpl
 | 
			
		||||
		&& npm install xrpl
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Using xrpl.js with Deno
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user