diff --git a/package.json b/package.json index c8c1b77..a499346 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "fontaine": "^0.4.1", "globby": "^14.0.1", "h3": "^1.10.2", + "jiti": "^1.21.0", "magic-string": "^0.30.7", "ofetch": "^1.3.3", "ohash": "^1.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f47c62..f3655c5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: h3: specifier: ^1.10.2 version: 1.10.2 + jiti: + specifier: ^1.21.0 + version: 1.21.0 magic-string: specifier: ^0.30.7 version: 0.30.7 diff --git a/src/module.ts b/src/module.ts index b26cc1d..dd09287 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,4 +1,5 @@ -import { addBuildPlugin, addTemplate, defineNuxtModule, resolveAlias, resolvePath, useLogger } from '@nuxt/kit' +import { addBuildPlugin, addTemplate, defineNuxtModule, resolveAlias, resolvePath, useLogger, useNuxt } from '@nuxt/kit' +import jiti from 'jiti' import google from './providers/google' import local from './providers/local' @@ -140,6 +141,9 @@ export default defineNuxtModule({ }) async function resolveProviders (_providers: ModuleOptions['providers'] = {}) { + const nuxt = useNuxt() + const _jiti = jiti(nuxt.options.rootDir, { interopDefault: true }) + const providers = { ..._providers } for (const key in providers) { const value = providers[key] @@ -147,7 +151,7 @@ async function resolveProviders (_providers: ModuleOptions['providers'] = {}) { delete providers[key] } if (typeof value === 'string') { - providers[key] = await import(await resolvePath(resolveAlias(value))) + providers[key] = await _jiti(await resolvePath(resolveAlias(value))) } } return providers as Record