import defu from 'defu' ; import { resolve } from 'pathe' ; import { defineNuxtModule , addPlugin } from '@nuxt/kit' ; import type { Nuxt } from '@nuxt/schema' ; import type { CookieOptions } from 'nuxt3/dist/app/composables/cookie' ; export interface ModuleOptions { default example type string url ? : string ; default type string prefix ? : string ; default type string example version ? : 'v4' | 'v3' ; default type CookieOptions cookie ? : CookieOptions ; } export default defineNuxtModule < ModuleOptions > ( { meta : { name : '@nuxtjs/strapi' , configKey : 'strapi' , compatibility : { nuxt : '^3.0.0' , bridge : true } } , defaults : { url : process . env . STRAPI_URL || 'http://localhost:1337' , prefix : '/api' , version : 'v4' , cookie : { } } , setup ( options , nuxt ) { if ( ! options . url ) { throw new Error ( 'Missing `STRAPI_URL` in `.env`' ) ; } nuxt . options . publicRuntimeConfig . strapi = defu ( nuxt . options . publicRuntimeConfig . strapi , { url : options . url , prefix : options . prefix , version : options . version , cookie : options . cookie } ) ; const runtimeDir = resolve ( __dirname , './runtime' ) ; nuxt . options . build . transpile . push ( runtimeDir ) ; addPlugin ( resolve ( runtimeDir , 'strapi.plugin' ) ) ; nuxt . hook ( 'autoImports:dirs' , ( dirs ) => { dirs . push ( resolve ( runtimeDir , 'composables' ) ) ; } ) ; } } ) ; declare module '@nuxt/schema' { interface ConfigSchema { publicRuntimeConfig ? : { strapi ? : ModuleOptions ; } ; } interface NuxtConfig { strapi ? : ModuleOptions ; } interface NuxtOptions { strapi ? : ModuleOptions ; } }