ArweaveKit in Browser Environments
Sample configurations needed for using ArweaveKit in Browser Environments
In today's web development landscape, module bundlers and frameworks play a pivotal role in optimizing and deploying code for browser environments. Despite their numerous advantages, it's important to note that these bundlers often require separate polyfill configurations to ensure support for Node's Core Modules across different browsers.
NextJS
NextJS is compatible with ArweaveKit out of the box and does not require separate polyfills for the modules.
NuxtJS
Nuxt 3 requires the implementation of polyfills in order to use the core modules in browser environments. Since Nuxt ships with Vite by default, we can use the Vite plugin for the same.
Setup
Here's a sample setup to successfully polyfill required modules and use the functionality from arweavekit in a Nuxt app.
The first step is installing the dependency:
Then this polyfill plugin must be added to the nuxt.config.ts
file and the nuxt config should look similar to the config below:
This is a sample config. For more advanced options visit here.
Now, add arweavekit plugin named arweavekit.client.ts
to the plugins
directory in the root directory of the nuxt project. And, import and return the essential functions from arweavekit in this plugin.
Now, you can use the functions from this plugin in your vue files as below.
Vite
In an attempt to prevent runtime errors, Vite produces errors or warnings when your code references built-in modules such as fs
or path
. These must be polyfilled separately to utilize the core modules in browser environments.
Setup
Here's a sample setup to successfully polyfill required modules in a Vite app.
The first step is installing the dependency:
Then the plugin must be added to the vite.config.js
file:
This is a sample config. For more advanced options visit here.
This config is compatible with all Vite-supported frameworks. Read more about the supported frameworks here.
Webpack
Webpack versions < 5 used to include polyfills by default, however, this must be implemented separately for Webpack versions > 5 in order to use the core modules in browser environments.
Setup
Here's a sample setup to successfully polyfill required modules in an app using Webpack as a bundler.
The first step is installing the dependency:
Then the setups must be added to a craco.config.js
file:
And finally, replace the default scripts in package.json
as follows:
This is a sample config. For more advanced options visit here.
This config is compatible with React applications. Learn more about React applications here.
Last updated