Skip to content

Commit

Permalink
feat: usePinia composable
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored and posva committed Jul 13, 2022
1 parent d15b061 commit c7debd6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 3 additions & 6 deletions packages/nuxt/playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { defineNuxtConfig } from 'nuxt'
import MyModule from '..'
import piniaModule from '../src/module'

export default defineNuxtConfig({
modules: [
MyModule
],
myModule: {
addPlugin: true
}
piniaModule
]
})
2 changes: 1 addition & 1 deletion packages/nuxt/playground/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"private": true,
"name": "my-module-playground"
"name": "pinia-nuxt-playground"
}
4 changes: 3 additions & 1 deletion packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export default defineNuxtModule<ModuleOptions>({
}

// Add auto imports
const composables = resolve(runtimeDir, './composables')
addAutoImport([
{ from: 'pinia', name: 'defineStore', as: 'definePiniaStore' },
{ from: composables, name: 'usePinia' },
{ from: composables, name: 'definePiniaStore' }
])
},
})
6 changes: 6 additions & 0 deletions packages/nuxt/src/runtime/composables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useNuxtApp } from '#imports'
import { defineStore } from 'pinia'

export const usePinia = () => useNuxtApp().$pinia

export const definePiniaStore = defineStore

0 comments on commit c7debd6

Please sign in to comment.