* @default `true`
*/
disableVuex?: boolean
+
+ /**
+ * Array of auto imports to be added to the nuxt.config.js file.
+ *
+ * @example
+ * ```js
+ * autoImports: [
+ * // automatically import `defineStore`
+ * 'defineStore',
+ * // automatically import `defineStore` as `definePiniaStore`
+ * ['defineStore', 'definePiniaStore',
+ * ]
+ * ```
+ *
+ */
+ autoImports?: Array<string | [string, string]>
}
export default defineNuxtModule<ModuleOptions>({
},
defaults: {
disableVuex: true,
+ autoImports: [],
},
setup(options, nuxt) {
const resolver = createResolver(import.meta.url)
const composables = resolver.resolve('./runtime/composables')
addAutoImport([
{ from: composables, name: 'usePinia' },
- { from: composables, name: 'definePiniaStore' },
+ ...options.autoImports.map((imports) =>
+ typeof imports === 'string'
+ ? { from: composables, name: imports }
+ : { from: composables, name: imports[0], as: imports[1] }
+ ),
])
},
})
import { useNuxtApp } from '#imports'
-import { defineStore } from 'pinia'
+export * from 'pinia'
export const usePinia = () => useNuxtApp().$pinia
-
-export const definePiniaStore = defineStore