From 3f25fda9cac56d3cb0315740d1872ff832927213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Ollivier?= Date: Thu, 17 Feb 2022 15:52:15 +0100 Subject: [PATCH 01/10] doc(aliases): change #app to #imports in snippets --- docs/content/1.getting-started/3.bridge.md | 6 ++--- .../4.bridge-composition-api.md | 22 +++++++++---------- docs/content/2.concepts/5.typescript.md | 2 +- docs/content/3.docs/1.usage/3.meta-tags.md | 2 ++ docs/content/3.docs/1.usage/4.nuxt-app.md | 2 +- .../3.docs/1.usage/5.runtime-config.md | 2 ++ docs/content/3.docs/1.usage/6.cookies.md | 2 ++ .../2.directory-structure/11.plugins.md | 6 ++--- .../2.directory-structure/5.composables.md | 4 ++-- .../3.docs/2.directory-structure/6.layouts.md | 2 ++ .../2.directory-structure/7.middleware.md | 2 ++ docs/content/3.docs/4.advanced/2.modules.md | 6 +++++ 12 files changed, 37 insertions(+), 21 deletions(-) diff --git a/docs/content/1.getting-started/3.bridge.md b/docs/content/1.getting-started/3.bridge.md index 61dd509d63c..a49486d1081 100644 --- a/docs/content/1.getting-started/3.bridge.md +++ b/docs/content/1.getting-started/3.bridge.md @@ -136,7 +136,7 @@ You may also need to add `@vue/runtime-dom` as a devDependency if you are strugg :: ::alert Keep in mind that all options extended from `./.nuxt/tsconfig.json` will be overwritten by the options defined in your `tsconfig.json`. -Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead Typescript to not factor in the module resolutions from `./.nuxt/tsconfig.json`. This can lead to module resolutions such as `#app` not being recognized. +Overwriting options such as `"compilerOptions.paths"` with your own configuration will lead Typescript to not factor in the module resolutions from `./.nuxt/tsconfig.json`. This can lead to module resolutions such as `#imports` not being recognized. In case you need to extend options provided by `./.nuxt/tsconfig.json` further, you can use the `alias` property withing your `nuxt.config`. `nuxi` will pick them up and extend `./.nuxt/tsconfig.json` accordingly. :: @@ -184,7 +184,7 @@ You can now migrate to the Nuxt 3 plugins API, which is slightly different in fo Plugins now take only one argument (`nuxtApp`). You can find out more in [the docs](/docs/directory-structure/plugins). ```js -import { defineNuxtPlugin } from '#app' +import { defineNuxtPlugin } from '#imports' export default defineNuxtPlugin(nuxtApp => { nuxtApp.provide('injected', () => 'my injected function') @@ -202,7 +202,7 @@ Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new `useM ```vue ``` @@ -174,13 +174,13 @@ You can access injected helpers using `useNuxtApp`. ```diff - import { useContext } from '@nuxtjs/composition-api` -+ import { useNuxtApp } from '#app' ++ import { useNuxtApp } from '#imports' + const { $axios } = useNuxtApp() ``` ```vue ``` @@ -213,7 +213,7 @@ Migrating to the new composables from `useAsync`: ```diff diff --git a/docs/content/3.docs/2.directory-structure/11.plugins.md b/docs/content/3.docs/2.directory-structure/11.plugins.md index 3959b234ef8..abe1bc8f0e6 100644 --- a/docs/content/3.docs/2.directory-structure/11.plugins.md +++ b/docs/content/3.docs/2.directory-structure/11.plugins.md @@ -34,7 +34,7 @@ Only `myPlugin.ts` and `myOtherPlugin/index.ts` would be registered. The only argument passed to a plugin is [`nuxtApp`](/docs/usage/nuxt-app). ```ts -import { defineNuxtPlugin } from '#app' +import { defineNuxtPlugin } from '#imports' export default defineNuxtPlugin(nuxtApp => { // Doing something with nuxtApp @@ -46,7 +46,7 @@ export default defineNuxtPlugin(nuxtApp => { If you would like to provide a helper on the `NuxtApp` instance, just return it from the plugin under a `provide` key. For example: ```ts -import { defineNuxtPlugin } from '#app' +import { defineNuxtPlugin } from '#imports' export default defineNuxtPlugin(() => { return { @@ -115,7 +115,7 @@ yarn add --dev vue-gtag-next Then create a plugin file `plugins/vue-gtag.client.js`. ```ts -import { defineNuxtPlugin } from '#app' +import { defineNuxtPlugin } from '#imports' import VueGtag from 'vue-gtag-next' export default defineNuxtPlugin((nuxtApp) => { diff --git a/docs/content/3.docs/2.directory-structure/5.composables.md b/docs/content/3.docs/2.directory-structure/5.composables.md index 3e6594fd9e1..19820e777db 100644 --- a/docs/content/3.docs/2.directory-structure/5.composables.md +++ b/docs/content/3.docs/2.directory-structure/5.composables.md @@ -27,7 +27,7 @@ Only `useFoo.ts` and `useBar/index.ts` would be searched for imports - and if th ## Example: (using named export) ```js [composables/useFoo.ts] -import { useState } from '#app' +import { useState } from '#imports' export const useFoo = () => { return useState('foo', () => 'bar') @@ -37,7 +37,7 @@ export const useFoo = () => { ## Example: (using default export) ```js [composables/use-foo.ts or composables/useFoo.ts] -import { useState } from '#app' +import { useState } from '#imports' // It will be available as useFoo() (camelCase of file name without extension) export default function () { diff --git a/docs/content/3.docs/2.directory-structure/6.layouts.md b/docs/content/3.docs/2.directory-structure/6.layouts.md index 591d641d27f..1793eb17c72 100644 --- a/docs/content/3.docs/2.directory-structure/6.layouts.md +++ b/docs/content/3.docs/2.directory-structure/6.layouts.md @@ -77,6 +77,8 @@ You can also use a ref or computed property for your layout. +``` + +## Vue auto-imports + +Vue 3 exposes Reactivity APIs like `ref` or `computed`, as well as lifecycle hooks and helpers that are auto-imported by Nuxt. + +```vue + +``` + +## Directory based auto-imports + +Nuxt directly auto-imports files created in defined directories: + +- `components/` for [Vue components](/docs/directory-structure/components). +- `composables/` for [Vue composables](/docs/directory-structure/composables). + +## Explicit imports + +Every Nuxt auto-import is exposed by the `#imports` alias that can be used to make the import explicit if needed: + +```vue + +``` diff --git a/docs/content/2.concepts/4.esm.md b/docs/content/2.concepts/5.esm.md similarity index 100% rename from docs/content/2.concepts/4.esm.md rename to docs/content/2.concepts/5.esm.md diff --git a/docs/content/2.concepts/5.typescript.md b/docs/content/2.concepts/6.typescript.md similarity index 100% rename from docs/content/2.concepts/5.typescript.md rename to docs/content/2.concepts/6.typescript.md From b0fa9c0e931116f7c0bc327e23de037b4bf36fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Ollivier?= Date: Fri, 18 Feb 2022 11:28:30 +0100 Subject: [PATCH 03/10] docs(imports): remove imports in snippets --- docs/content/1.getting-started/3.bridge.md | 3 --- docs/content/3.docs/1.usage/3.meta-tags.md | 2 -- docs/content/3.docs/1.usage/4.nuxt-app.md | 2 -- docs/content/3.docs/1.usage/5.runtime-config.md | 2 -- docs/content/3.docs/1.usage/6.cookies.md | 2 -- docs/content/3.docs/2.directory-structure/10.pages.md | 5 +---- docs/content/3.docs/2.directory-structure/11.plugins.md | 5 ----- docs/content/3.docs/2.directory-structure/5.composables.md | 4 ---- docs/content/3.docs/2.directory-structure/6.layouts.md | 2 -- docs/content/3.docs/2.directory-structure/7.middleware.md | 2 -- 10 files changed, 1 insertion(+), 28 deletions(-) diff --git a/docs/content/1.getting-started/3.bridge.md b/docs/content/1.getting-started/3.bridge.md index a49486d1081..d6df60a566c 100644 --- a/docs/content/1.getting-started/3.bridge.md +++ b/docs/content/1.getting-started/3.bridge.md @@ -184,8 +184,6 @@ You can now migrate to the Nuxt 3 plugins API, which is slightly different in fo Plugins now take only one argument (`nuxtApp`). You can find out more in [the docs](/docs/directory-structure/plugins). ```js -import { defineNuxtPlugin } from '#imports' - export default defineNuxtPlugin(nuxtApp => { nuxtApp.provide('injected', () => 'my injected function') // now available on `nuxtApp.$injected` @@ -202,7 +200,6 @@ Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new `useM ```vue diff --git a/docs/content/3.docs/2.directory-structure/10.pages.md b/docs/content/3.docs/2.directory-structure/10.pages.md index dd6f2210f0d..574578dfe78 100644 --- a/docs/content/3.docs/2.directory-structure/10.pages.md +++ b/docs/content/3.docs/2.directory-structure/10.pages.md @@ -48,11 +48,8 @@ admins 123 If you want to access the route using Composition API, there is a global `useRoute` function that will allow you to access the route just like `this.$route` in the Options API. -```js +```vue ``` @@ -52,7 +52,7 @@ Every Nuxt auto-import is exposed by the `#imports` alias that can be used to ma ``` From d68c9a630a6a435dba7d475c9f0bfa6f0070ccee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Ollivier?= Date: Fri, 18 Feb 2022 16:14:21 +0100 Subject: [PATCH 06/10] docs(imports): remove imports in bridge composition api docs --- .../4.bridge-composition-api.md | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/docs/content/1.getting-started/4.bridge-composition-api.md b/docs/content/1.getting-started/4.bridge-composition-api.md index 48e2e1fe07e..bce6eb73800 100644 --- a/docs/content/1.getting-started/4.bridge-composition-api.md +++ b/docs/content/1.getting-started/4.bridge-composition-api.md @@ -35,11 +35,14 @@ Because some composables have been removed and don't yet have a replacement, thi * `useStatic` has been removed. There is no current replacement. Feel free to raise a discussion if you have a use case for this. * `reqRef` and `reqSsrRef`, which were deprecated, have now been removed entirely. Follow the instructions below regarding [ssrRef](#ssrref-and-shallowssrref) to replace this. -2. Remove any explicit imports of the basic Vue Composition API composables, or move them to import from `#imports` or `vue`. +2. Remove any explicit imports of the basic Vue Composition API composables. + +::alert{type=info} +Nuxt Bridge [auto-imports](/concepts/auto-imports) Vue composables, you don't have to explicitly import them. +:: ```diff - import { ref, useContext } from '@nuxtjs/composition-api` - + import { ref } from '#imports' ``` 3. For each other composable you are using from `@nuxtjs/composition-api`, follow the steps below. @@ -48,7 +51,7 @@ Because some composables have been removed and don't yet have a replacement, thi This was a type-helper stub function that is now removed. -Simply remove the `defineNuxtMiddleware` wrapper: +Remove the `defineNuxtMiddleware` wrapper: ```diff - import { defineNuxtMiddleware } from '@nuxtjs/composition-api` @@ -68,9 +71,9 @@ export default function (ctx) { } This was a type-helper stub function that is now removed. -You may also keep using Nuxt 2-style plugins, by simply removing the function (as with [defineNuxtMiddleware](#definenuxtmiddleware)). +You may also keep using Nuxt 2-style plugins, by removing the function (as with [defineNuxtMiddleware](#definenuxtmiddleware)). -Simply remove the `defineNuxtPlugin` wrapper: +Remove the `defineNuxtPlugin` wrapper: ```diff - import { defineNuxtPlugin } from '@nuxtjs/composition-api` @@ -96,7 +99,6 @@ This function has been removed, but its use cases can be met by using `useNuxtAp ```diff - import { onGlobalSetup } from '@nuxtjs/composition-api' -+ import { defineNuxtPlugin } from '#imports' - export default () => { - onGlobalSetup(() => { @@ -116,7 +118,6 @@ The key differences are that you must provide a _key_ for this state (which prev ```diff - import { ssrRef } from '@nuxtjs/composition-api' -+ import { useState } from '#imports' - const ref1 = ssrRef('initialData') - const ref2 = ssrRef(() => 'factory function') @@ -142,7 +143,6 @@ The only key difference is that `useRoute` no longer returns a computed property ```diff - import { useRouter, useRoute } from '@nuxtjs/composition-api' -+ import { useRouter, useRoute } from '#imports' const router = useRouter() const route = useRoute() @@ -157,34 +157,18 @@ In order to access Vuex store instance, you can use `useNuxtApp().$store`. ```diff - import { useStore } from '@nuxtjs/composition-api` -+ import { useNuxtApp } from '#imports' + const { $store } = useNuxtApp() ``` -```vue - -``` - ### `useContext` and `withContext` You can access injected helpers using `useNuxtApp`. ```diff - import { useContext } from '@nuxtjs/composition-api` -+ import { useNuxtApp } from '#imports' + const { $axios } = useNuxtApp() ``` -```vue - -``` - ::alert{icon=👉} `useNuxtApp()` also provides a key called `nuxt2Context` which contains all the same properties you would normally access from Nuxt 2 context, but it's advised _not_ to use this directly, as it won't exist in Nuxt 3. Instead, see if there is another way to access what you need. (If not, please raise a feature request or discussion.) :: @@ -213,7 +197,6 @@ Migrating to the new composables from `useAsync`: ```diff