]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
auto imports
authorPooya Parsa <pooya@pi0.io>
Fri, 8 Jul 2022 11:05:42 +0000 (13:05 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Wed, 13 Jul 2022 10:32:58 +0000 (12:32 +0200)
packages/nuxt/package.json
packages/nuxt/playground/composables/counter.ts
packages/nuxt/src/module.ts
pnpm-lock.yaml

index 9524d175d4e06faad4ee034f3d6e87237c0ec1da..c3f476edf1f3ad6c9c5eaeb48d40640f517013d2 100644 (file)
@@ -38,6 +38,7 @@
   ],
   "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",
index a5cc9444aabfd02b3efe2a3680951a1441d94b10..ca32b6a5821cfd08c65130167bf69a7b7cd4e00a 100644 (file)
@@ -1,6 +1,4 @@
-import { defineStore, acceptHMRUpdate } from 'pinia'
-
-export const useCounter = defineStore('counter', {
+export const useCounter = definePiniaStore('counter', {
   state: () => ({
     count: 100
   }),
@@ -13,7 +11,3 @@ export const useCounter = defineStore('counter', {
     getCount: state => state.count
   }
 })
-
-if (import.meta.hot) {
-  import.meta.hot.accept(acceptHMRUpdate(useCounter, import.meta.hot))
-}
index 4d82a03a15760d6054d17b8c74b97be566eabec8..7e40734371e002640670d6bf17d799287acf4e6d 100644 (file)
@@ -1,11 +1,11 @@
-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`
    */
@@ -27,7 +27,7 @@ export default defineNuxtModule<ModuleOptions>({
   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
     }
@@ -35,17 +35,19 @@ export default defineNuxtModule<ModuleOptions>({
     // 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' }
+    ])
   }
 })
index c349078c626b886a9a2bd2e48604ae30cc5ac1c8..13d44c72009f874907fca0be22984b8af9f95223 100644 (file)
@@ -716,7 +716,7 @@ packages:
     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
@@ -734,7 +734,7 @@ packages:
     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