File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -41,16 +41,22 @@ To configure Nuxt Query, update your `nuxt.config.ts` specifying the options you
4141export default defineNuxtConfig ({
4242 modules: [' @peterbud/nuxt-query' ],
4343 nuxtQuery: {
44- // Specify which Vue Query composable(s) to auto-import
44+ /**
45+ * Specify which Vue Query composable(s) to auto-import
46+ * Default to `false`, set to `true` to auto-import all Vue Query composables
47+ */
4548 autoImports: [' useQuery' , ' useMutation' ],
4649
4750 // Enable / disable Nuxt DevTools integration (default: true).
4851 devtools: true ,
4952
50- // These are the same options as the QueryClient
51- // from @tanstack/vue-query, will be passed
52- // to the QueryClient constructor
53- // More details: https://tanstack.com/query/v5/docs/reference/QueryClient
53+ /**
54+ * These are the same options as the QueryClient
55+ * from @tanstack/vue-query, which will be passed
56+ * to the QueryClient constructor
57+ * More details: https://tanstack.com/query/v5/docs/reference/QueryClient
58+ */
59+
5460 queryClientOptions: {
5561 defaultOptions: {
5662 queries: {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const _composables = [
1717type VueQueryComposables = typeof _composables [ number ]
1818
1919export interface ModuleOptions {
20- autoImports : VueQueryComposables [ ] | false
20+ autoImports : VueQueryComposables [ ] | boolean
2121 devtools : boolean
2222 queryClientOptions : QueryClientConfig | undefined
2323}
@@ -71,8 +71,17 @@ export default defineNuxtModule<ModuleOptions>({
7171 addPlugin ( resolver . resolve ( './runtime/plugin' ) )
7272
7373 // Auto imports tanstack composables
74- if ( options . autoImports && options . autoImports . length > 0 )
75- addImports ( options . autoImports . map ( name => ( { name, from : '@tanstack/vue-query' } ) ) )
74+ let importComposables = new Set < VueQueryComposables > ( _composables )
75+ if ( typeof options . autoImports === 'boolean' ) {
76+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
77+ ! options . autoImports && importComposables . clear ( )
78+ }
79+ else {
80+ importComposables = importComposables . intersection ( new Set ( options . autoImports ) )
81+ }
82+ addImports ( [ ...importComposables . values ( ) ] . map ( name => (
83+ { name, from : '@tanstack/vue-query' }
84+ ) ) )
7685
7786 if ( options . devtools )
7887 setupDevToolsUI ( nuxt , resolver )
You can’t perform that action at this time.
0 commit comments