Skip to content

Commit 087b92f

Browse files
Bojan Angjelkoskigitbook-bot
authored andcommitted
GITBOOK-95: change request with no subject merged in GitBook
1 parent 46df99a commit 087b92f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

.gitbook/building-dapps/configuring-react.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,28 @@ These are the most commonly used packages from the `injective-ts` monorepo.
2727

2828
### 3. Configuring Vite and adding polyfills
2929

30-
First, add the needed polyfill packages
30+
First, add the needed polyfill packages and buffer 
31+
32+
{% hint style="info" %}
33+
One of the main dependencies for any crypto-related decentralized application is `Buffer`. To make sure we add `Buffer` To our project, we can install it as a dependency and then make a import it to the global/window object).
34+
35+
Example `vite.config.ts` is shared below.
36+
{% endhint %}
3137

3238
```bash
33-
$ yarn add @bangjelkoski/vite-plugin-node-polyfills
39+
$ yarn add @bangjelkoski/node-stdlib-browser
40+
$ yarn add -D @bangjelkoski/vite-plugin-node-polyfills
41+
$ yarn add buffer
42+
```
43+
44+
Finally, make sure to import the `buffer` in your `main.tsx` on top of the file
45+
46+
```typescript
47+
import { Buffer } from "buffer";
48+
49+
if (!window.Buffer) {
50+
window.Buffer = Buffer; // Optional, for packages expecting Buffer to be global
51+
}
3452
```
3553

3654
### 4. Using a state management
@@ -57,6 +75,18 @@ import { nodePolyfills } from "@bangjelkoski/vite-plugin-node-polyfills";
5775
// https://vitejs.dev/config/
5876
export default defineConfig({
5977
plugins: [react(), nodePolyfills({ protocolImports: true })],
78+
define: {
79+
global: "globalThis",
80+
},
81+
resolve: {
82+
alias: {
83+
// others
84+
buffer: "buffer/",
85+
},
86+
},
87+
optimizeDeps: {
88+
include: ["buffer"],
89+
},
6090
});
6191
```
6292

0 commit comments

Comments
 (0)