],
"scripts": {
"prepack": "nuxt-module-build",
+ "build": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
-import { defineStore, acceptHMRUpdate } from 'pinia'
-
-export const useCounter = defineStore('counter', {
+export const useCounter = definePiniaStore('counter', {
state: () => ({
count: 100
}),
getCount: state => state.count
}
})
-
-if (import.meta.hot) {
- import.meta.hot.accept(acceptHMRUpdate(useCounter, import.meta.hot))
-}
-import { resolve } from 'node:path'
-import { fileURLToPath } from 'node:url'
-import { defineNuxtModule, addPlugin, isNuxt2 } from '@nuxt/kit'
+import { resolve } from 'path'
+import { fileURLToPath } from 'url'
+import { defineNuxtModule, addPlugin, isNuxt2, addAutoImport } from '@nuxt/kit'
export interface ModuleOptions {
/**
* Pinia disables Vuex by default, set this option to `false` to avoid it and
- * use Pinia alongside Vuex.
+ * use Pinia alongside Vuex (Nuxt 2 only)
*
* @default `true`
*/
setup (options: ModuleOptions, nuxt) {
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
- // Disable default Vuex store (options.features only exists in Nuxt v2.10+)
+ // Disable default Vuex store (Nuxt v2.10+ only)
if (nuxt.options.features && options.disableVuex && isNuxt2()) {
nuxt.options.features.store = false
}
// Transpile runtime
nuxt.options.build.transpile.push(runtimeDir)
- // 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
+ // Make sure we use the mjs build for pinia
nuxt.options.alias.pinia = 'pinia/dist/pinia.mjs'
- nuxt.options.build.transpile.push('pinia')
// Add runtime plugin
if (isNuxt2()) {
addPlugin(resolve(runtimeDir, './plugin.vue2'))
-
} else {
addPlugin(resolve(runtimeDir, './plugin'))
}
+
+ // Add auto imports
+ addAutoImport([
+ { from: 'pinia', name: 'defineStore', as: 'definePiniaStore' }
+ ])
}
})
resolution: {integrity: sha512-I8j/x8kHUrbYRTUxXrrMbfCa7jxkE7tZre39x3kjr9hvI82cK1FfqLygotcWN5kdPGWcLdWMHpSBavse5tWw3w==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/code-frame': 7.16.7
+ '@babel/code-frame': 7.18.6
'@babel/parser': 7.18.5
'@babel/types': 7.18.4
dev: true
resolution: {integrity: sha512-aKXj1KT66sBj0vVzk6rEeAO6Z9aiiQ68wfDgge3nHhA/my6xMM/7HGQUNumKZaoa2qUPQ5whJG9aAifsxUKfLA==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/code-frame': 7.16.7
+ '@babel/code-frame': 7.18.6
'@babel/generator': 7.18.2
'@babel/helper-environment-visitor': 7.18.2
'@babel/helper-function-name': 7.17.9