]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(nuxt): automatically add pinia types (#1551)
authorDaniel Roe <daniel@roe.dev>
Tue, 16 Aug 2022 15:16:54 +0000 (16:16 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Aug 2022 15:16:54 +0000 (17:16 +0200)
packages/docs/ssr/nuxt.md
packages/nuxt/src/module.ts

index 05ee3af96b3ac7632abc7577a4100f090d6bfa42..df302f12db0ea57a7393ffe6a2c55668f68a4b0d 100644 (file)
@@ -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:
index 4fd3ddd8f38bca583d37e2632a09431a8041c307..a130303a5788a5af7604c6e31c188eb9e2b53a30 100644 (file)
@@ -65,6 +65,10 @@ export default defineNuxtModule<ModuleOptions>({
       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'))