-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathindex.ts
69 lines (60 loc) · 1.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @module @pinia/nuxt
*/
import { addPlugin, defineNuxtModule } from '@nuxt/kit'
import { isVue2 } from 'vue-demi'
import type { Pinia } from 'pinia'
import type { Context } from '@nuxt/types'
export interface PiniaNuxtOptions {
/**
* Pinia disables Vuex by default, set this option to `false` to avoid it and
* use Pinia alongside Vuex.
*
* @default `true`
*/
disableVuex?: boolean
}
const module = defineNuxtModule<PiniaNuxtOptions>({
name: 'pinia',
configKey: 'pinia',
defaults: {
disableVuex: true,
},
setup(options, nuxt) {
// Disable default Vuex store (options.features only exists in Nuxt v2.10+)
if (nuxt.options.features && options.disableVuex) {
nuxt.options.features.store = false
}
// make sure we use the mjs for pinia so node doesn't complain about using a module js with an extension that is js
// but doesn't have the type: module in its packages.json file
nuxt.options.alias.pinia = 'pinia/dist/pinia.mjs'
addPlugin({ src: require.resolve('./templates/plugin.mjs') })
// transpile pinia for nuxt 2 and nuxt bridge
if (isVue2 && !nuxt.options.build.transpile.includes('pinia')) {
nuxt.options.build.transpile.push('pinia')
}
},
})
export default module
declare module '@nuxt/types' {
export interface Context {
/**
* Pinia instance attached to the app.
*
* @deprecated: use context.$pinia instead
*/
pinia: Pinia
/**
* Pinia instance attached to the app.
*/
$pinia: Pinia
}
}
declare module 'pinia' {
export interface PiniaCustomProperties {
/**
* Nuxt context.
*/
$nuxt: Context
}
}