Skip to content

Commit

Permalink
Merge pull request #166 from Govrn-HQ/fix/polyfill-buffer
Browse files Browse the repository at this point in the history
polyfill buffer for WalletConnect on RainbowKit
  • Loading branch information
scottrepreneur committed Aug 30, 2022
2 parents 579f1a9 + 64b0b8a commit 60a7fa2
Show file tree
Hide file tree
Showing 5 changed files with 710 additions and 699 deletions.
6 changes: 3 additions & 3 deletions apps/protocol-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<link href="/src/assets/favicon.png" rel="icon" type="image/svg+xml" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Govrn</title>
<script>
window.global = window;
</script>
</head>
<body>
<div id="root"></div>
<script src="/src/main.tsx" type="module"></script>
<script>
window.global = window;
</script>
</body>
</html>
15 changes: 10 additions & 5 deletions apps/protocol-frontend/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* Polyfill stable language features. These imports will be optimized by `@babel/preset-env`.
*
* See: https://github.com/zloirock/core-js#babel
*/
import { Buffer } from 'buffer';

window.Buffer = window.Buffer ?? Buffer;
window.process = window.process ?? { env: {} }; // Minimal process polyfill

export {};

/*
// If we see issues with 'regenerator-runtime', add back these imports
import 'core-js/stable';
import 'regenerator-runtime/runtime';
*/
44 changes: 15 additions & 29 deletions apps/protocol-frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
import GlobalPolyFill from '@esbuild-plugins/node-globals-polyfill';
import { defineConfig } from 'vite';
import { resolve } from 'path';
import tsconfigPaths from 'vite-tsconfig-paths';
import { viteExternalsPlugin } from 'vite-plugin-externals';

const externalPlugin = viteExternalsPlugin({
...{
electron: 'electron',
'electron-fetch': 'electron-fetch',
},
});

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
tsconfigPaths({
root: '../..',
}),
externalPlugin,
],
resolve: {
alias: {
stream: 'stream-browserify',
url: 'url-browserify',
http: 'http-browserify',
https: 'http-browserify',
process: 'process-es6',
'~~': resolve(__dirname, 'src'),
},
},
build: {
target: 'esnext',
commonjsOptions: {
transformMixedEsModules: true,
},
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
// my fix
'globalThis.process.env.NODE_ENV': 'development',
},
plugins: [
GlobalPolyFill({
process: true,
buffer: true,
}),
],
},
},
resolve: {
alias: {
process: 'process/browser',
stream: 'stream-browserify',
zlib: 'browserify-zlib',
util: 'util',
},
},
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@chakra-ui/react": "^1.8.8",
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@fontsource/inter": "^4.5.10",
"@graphprotocol/graph-ts": "^0.27.0",
"@graphql-codegen/cli": "^2.6.2",
Expand All @@ -34,7 +35,7 @@
"@nx-tools/nx-docker": "^2.3.0",
"@prisma/client": "^3.12.0",
"@qualifyze/airtable": "^2.0.1",
"@rainbow-me/rainbowkit": "^0.4.5",
"@rainbow-me/rainbowkit": "^0.4.7",
"@rollup/plugin-strip": "^2.1.0",
"@stablelib/random": "^1.0.1",
"@types/express-session": "^1.17.4",
Expand All @@ -48,6 +49,7 @@
"airtable": "^0.11.2",
"apg-js": "^4.1.2",
"axios": "^0.26.0",
"buffer": "^6.0.3",
"class-validator": "^0.13.2",
"cookie-session": "^2.0.0",
"core-js": "^3.6.5",
Expand Down Expand Up @@ -134,7 +136,7 @@
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "~5.10.0",
"@typescript-eslint/parser": "~5.10.0",
"@vitejs/plugin-react": "^1.2.0",
"@vitejs/plugin-react": "^1.3.0",
"babel-jest": "27.2.3",
"babel-loader": "8.1.0",
"buffer-es6": "^4.9.3",
Expand Down Expand Up @@ -172,7 +174,7 @@
"typescript": "^4.7.4",
"url-loader": "^3.0.0",
"url-polyfill": "^1.1.12",
"vite": "^2.8.0",
"vite": "^2.9.9",
"vite-plugin-eslint": "1.3.0"
}
}

0 comments on commit 60a7fa2

Please sign in to comment.