Nuxt configuration

Nuxt3 - The Intuitive Web Framework

The preferred choice of UI framework to build decentralized applications on top of Injective at @InjectiveLabs is Nuxt3. We are going to help you configure Nuxt3 + the Vite builder with the @injectivelabs packages and some polyfills since you'll need them to interact with Crypto wallets.

1. Installing Nuxt 3

Follow the Getting Started guide at Nuxt3 Docs and setup your application.

2. Installing @injectivelabs packages

You can install the @injectivelabs packages using yarn.

$ yarn add @injectivelabs/sdk-ts @injectivelabs/networks @injectivelabs/ts-types @injectivelabs/utils

## If you need Wallet Connection
$ yarn add @injectivelabs/wallet-strategy

These are the most commonly used packages from the injective-ts monorepo.

3. Configuring Nuxt and adding polyfills

First, add the needed polyfill packages

$ yarn add @bangjelkoski/node-stdlib-browser
$ yarn add -D @bangjelkoski/vite-plugin-node-polyfills

Make sure you are using the [email protected] , nuxt@^3.8.1, typescript@^5.0.4 versions.

Buffer

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 Nuxt plugin to import it to the global/window object:

4. Using a state management

If you are going to use pinia as state management, add it to your packages:

5. Using vueuse

We recommend adding @vueuse/nuxt as a dependency as it offers a lot of utility functions out of the box.

Then, we need to configure the tsconfig.json if you are using TypeScript (recommended). You can reference the following tsconfig.json as a base.

6. nuxt.config.ts / packages.json

Before we boot our application, we need to set everything up in the nuxt.config.ts, the main configuration point for every Nuxt 3 application. Let's see a reference nuxt.config.ts and explain every line using comments so it's easier for developers to understand.

There is one optimization that you can to decrease the bundle size - add these resolutions in the packages.json

7. Booting our app

Finally, you can start your app locally using yarn dev or generate static pages using yarn generate which you can deploy to any static page hosting like Netlify, Vercel, etc.

Last updated