11import { existsSync } from 'node:fs'
22import { createJiti } from 'jiti'
33import { defu } from 'defu'
4- import { useLogger , addPlugin , addImports , addTemplate , createResolver , defineNuxtModule } from '@nuxt/kit'
4+ import { useLogger , addPlugin , addImports , addTemplate , createResolver , defineNuxtModule , addVitePlugin } from '@nuxt/kit'
55import GraphQLPlugin from '@rollup/plugin-graphql'
66import type { PluginOption } from 'vite'
77import { name , version } from '../package.json'
@@ -25,7 +25,7 @@ export default defineNuxtModule<ModuleOptions>({
2525 version,
2626 configKey : 'apollo' ,
2727 compatibility : {
28- nuxt : '^3.0.0 || ^4.0.0'
28+ nuxt : '^3.0.0 || ^4.0.0 || ^5.0.0 '
2929 }
3030 } ,
3131 defaults : {
@@ -159,18 +159,22 @@ export default defineNuxtModule<ModuleOptions>({
159159 ] . map ( n => ( { name : n , from : '@vue/apollo-composable' } ) ) )
160160 ] )
161161
162- nuxt . hook ( 'vite:extendConfig' , ( config ) => {
163- config . optimizeDeps = config . optimizeDeps || { }
164- config . optimizeDeps . exclude = config . optimizeDeps . exclude || [ ]
165- config . optimizeDeps . exclude . push ( '@vue/apollo-composable' )
162+ addVitePlugin ( GraphQLPlugin ( ) )
166163
167- config . plugins = config . plugins || [ ]
168- config . plugins . push ( GraphQLPlugin ( ) as PluginOption )
169-
170- if ( ! nuxt . options . dev ) {
171- config . define = { ...config . define , __DEV__ : false }
164+ addVitePlugin ( ( ) => ( {
165+ name : 'apollo-composable-optimize-deps' ,
166+ configEnvironment ( name , config ) {
167+ // you can set environment-specific vite configuration here
168+ if ( name === 'client' ) {
169+ config . optimizeDeps ||= { }
170+ config . optimizeDeps . include ||= [ ]
171+ config . optimizeDeps . include . push ( '@vue/apollo-composable' )
172+ }
173+ } ,
174+ applyToEnvironment ( environment ) {
175+ return environment . name === 'client'
172176 }
173- } )
177+ } ) )
174178
175179 nuxt . hook ( 'webpack:config' , ( configs ) => {
176180 for ( const config of configs ) {
0 commit comments