From: Pooya Parsa Date: Fri, 8 Jul 2022 11:05:42 +0000 (+0200) Subject: auto imports X-Git-Tag: @pinia/nuxt@0.3.0~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=713795544f51ba1f28a5ac00161c4faaa925b999;p=thirdparty%2Fvuejs%2Fpinia.git auto imports --- diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 9524d175..c3f476ed 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -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", diff --git a/packages/nuxt/playground/composables/counter.ts b/packages/nuxt/playground/composables/counter.ts index a5cc9444..ca32b6a5 100644 --- a/packages/nuxt/playground/composables/counter.ts +++ b/packages/nuxt/playground/composables/counter.ts @@ -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)) -} diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 4d82a03a..7e407343 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -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({ 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({ // 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' } + ]) } }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c349078c..13d44c72 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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