From: Daniel Roe Date: Tue, 16 Aug 2022 15:16:54 +0000 (+0100) Subject: feat(nuxt): automatically add pinia types (#1551) X-Git-Tag: @pinia/nuxt@0.4.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ebfcd8bbaaaacba7d03c66ac67775448fb02363;p=thirdparty%2Fvuejs%2Fpinia.git feat(nuxt): automatically add pinia types (#1551) --- diff --git a/packages/docs/ssr/nuxt.md b/packages/docs/ssr/nuxt.md index 05ee3af9..df302f12 100644 --- a/packages/docs/ssr/nuxt.md +++ b/packages/docs/ssr/nuxt.md @@ -14,13 +14,13 @@ We supply a _module_ to handle everything for you, you only need to add it to `b ```js // nuxt.config.js -export default { +export default defineNuxtConfig({ // ... other options - buildModules: [ + modules: [ // ... '@pinia/nuxt', ], -} +}) ``` And that's it, use your store as usual! @@ -64,21 +64,6 @@ export default { } ``` -## TypeScript - -If you are using TypeScript or have a `jsconfig.json`, you should also add the types for `context.pinia`: - -```json -{ - "types": [ - // ... - "@pinia/nuxt" - ] -} -``` - -This will also ensure you have autocompletion 😉 . - ## Nuxt 2 without bridge Pinia supports Nuxt 2 until `@pinia/nuxt` v0.2.1. Make sure to also install [`@nuxtjs/composition-api`](https://composition-api.nuxtjs.org/) alongside `pinia`: @@ -104,6 +89,21 @@ export default { } ``` +### TypeScript + +If you are using Nuxt 2 (`@pinia/nuxt` < 0.3.0) with TypeScript or have a `jsconfig.json`, you should also add the types for `context.pinia`: + +```json +{ + "types": [ + // ... + "@pinia/nuxt" + ] +} +``` + +This will also ensure you have autocompletion 😉 . + ### Using Pinia alongside Vuex It is recommended to **avoid using both Pinia and Vuex** but if you need to use both, you need to tell pinia to not disable it: diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 4fd3ddd8..a130303a 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -65,6 +65,10 @@ export default defineNuxtModule({ paths: [nuxt.options.rootDir, import.meta.url], }) + nuxt.hook('prepare:types', ({ references }) => { + references.push({ types: '@pinia/nuxt' }) + }) + // Add runtime plugin if (isNuxt2()) { addPlugin(resolver.resolve('./runtime/plugin.vue2'))