N
Nuxt2y ago
toni

How to add modules to auto-imports?

In my app I have many components and pages with this import:
import { ethers, utils } from 'ethers'
import { ethers, utils } from 'ethers'
Is there a way to add it to auto-imports and potentially rename it, aka. utils to ethersUtils or smth like that?
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
toni
toniOP2y ago
Yes I thought the same and then somehow export it in a file under /utils, which will auto import it. Just couldn't figure out how to export a module. Second option would be imports in nuxt.config.ts, but it doesn't have much docs yet...
Zampa
Zampa2y ago
You could create a simple plugin that makes it available to all components:
import { ethers, utils as etherUtils } from 'ethers'
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.provide('ethers', {
ethers
});
nuxtApp.provide('etherUtils ', {
ethers
});
});
import { ethers, utils as etherUtils } from 'ethers'
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.provide('ethers', {
ethers
});
nuxtApp.provide('etherUtils ', {
ethers
});
});
Want results from more Discord servers?
Add your server