@nuxt/docs 4.1.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +6 -6
- package/1.getting-started/02.installation.md +3 -2
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +241 -110
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +22 -16
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +334 -85
- package/2.guide/3.going-further/1.features.md +58 -11
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +126 -108
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +76 -59
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +45 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +49 -18
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +26 -22
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +62 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +2 -2
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +123 -37
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +66 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +61 -4
- package/3.api/5.kit/15.examples.md +5 -7
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +8 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.head.md +132 -0
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +5 -5
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +365 -859
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +3 -3
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +2 -2
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -32,7 +32,7 @@ export { a }
|
|
|
32
32
|
|
|
33
33
|
Before ECMAScript Modules (ESM) became a standard (it took more than 10 years!), tooling like
|
|
34
34
|
[webpack](https://webpack.js.org/guides/ecma-script-modules) and even languages like TypeScript started supporting so-called **ESM syntax**.
|
|
35
|
-
However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive).
|
|
35
|
+
However, there are some key differences with actual spec; here's [a helpful explainer](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/).
|
|
36
36
|
|
|
37
37
|
### What is 'Native' ESM?
|
|
38
38
|
|
|
@@ -50,6 +50,10 @@ When adding modules to your package, things were a little different. A sample li
|
|
|
50
50
|
|
|
51
51
|
So in Nuxt 2, the bundler (webpack) would pull in the CJS file ('main') for the server build and use the ESM file ('module') for the client build.
|
|
52
52
|
|
|
53
|
+
::note
|
|
54
|
+
The `module` field is a convention used by bundlers like webpack and Rollup, but is not recognized by Node.js itself. Node.js only uses the [`exports`](https://nodejs.org/api/packages.html#exports) and [`main`](https://nodejs.org/api/packages.html#main) fields for module resolution.
|
|
55
|
+
::
|
|
56
|
+
|
|
53
57
|
However, in recent Node.js LTS releases, it is now possible to [use native ESM module](https://nodejs.org/api/esm.html) within Node.js. That means that Node.js itself can process JavaScript using ESM syntax, although it doesn't do it by default. The two most common ways to enable ESM syntax are:
|
|
54
58
|
|
|
55
59
|
- set `"type": "module"` within your `package.json` and keep using `.js` extension
|
|
@@ -59,7 +63,7 @@ This is what we do for Nuxt Nitro; we output a `.output/server/index.mjs` file.
|
|
|
59
63
|
|
|
60
64
|
### What Are Valid Imports in a Node.js Context?
|
|
61
65
|
|
|
62
|
-
When you `import` a module rather than `require` it, Node.js resolves it differently. For example, when you import `sample-library`, Node.js will look
|
|
66
|
+
When you `import` a module rather than `require` it, Node.js resolves it differently. For example, when you import `sample-library`, Node.js will look for the `exports` entry in that library's `package.json`, or fall back to the `main` entry if `exports` is not defined.
|
|
63
67
|
|
|
64
68
|
This is also true of dynamic imports, like `const b = await import('sample-library')`.
|
|
65
69
|
|
|
@@ -111,7 +115,7 @@ const { named } = pkg;
|
|
|
111
115
|
|
|
112
116
|
## Troubleshooting ESM Issues
|
|
113
117
|
|
|
114
|
-
If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](#library-author-guide) to support being imported by Node.
|
|
118
|
+
If you encounter these errors, the issue is almost certainly with the upstream library. They need to [fix their library](/docs/4.x/guide/concepts/esm#library-author-guide) to support being imported by Node.
|
|
115
119
|
|
|
116
120
|
### Transpiling Libraries
|
|
117
121
|
|
|
@@ -120,8 +124,8 @@ In the meantime, you can tell Nuxt not to try to import these libraries by addin
|
|
|
120
124
|
```ts twoslash
|
|
121
125
|
export default defineNuxtConfig({
|
|
122
126
|
build: {
|
|
123
|
-
transpile: ['sample-library']
|
|
124
|
-
}
|
|
127
|
+
transpile: ['sample-library'],
|
|
128
|
+
},
|
|
125
129
|
})
|
|
126
130
|
```
|
|
127
131
|
|
|
@@ -134,8 +138,8 @@ In some cases, you may also need to manually alias the library to the CJS versio
|
|
|
134
138
|
```ts twoslash
|
|
135
139
|
export default defineNuxtConfig({
|
|
136
140
|
alias: {
|
|
137
|
-
'sample-library': 'sample-library/dist/sample-library.cjs.js'
|
|
138
|
-
}
|
|
141
|
+
'sample-library': 'sample-library/dist/sample-library.cjs.js',
|
|
142
|
+
},
|
|
139
143
|
})
|
|
140
144
|
```
|
|
141
145
|
|
|
@@ -182,6 +186,8 @@ import('cjs-pkg').then(console.log) // [Module: null prototype] { default: { tes
|
|
|
182
186
|
|
|
183
187
|
In this case, we need to manually interop the default export:
|
|
184
188
|
|
|
189
|
+
<!-- eslint-disable import/no-named-default -->
|
|
190
|
+
|
|
185
191
|
```js
|
|
186
192
|
// Static import
|
|
187
193
|
import { default as pkg } from 'cjs-pkg'
|
|
@@ -219,16 +225,16 @@ The initial step from CJS to ESM is updating any usage of `require` to use `impo
|
|
|
219
225
|
|
|
220
226
|
::code-group
|
|
221
227
|
|
|
222
|
-
```
|
|
223
|
-
module.exports = ...
|
|
228
|
+
```ts [Before]
|
|
229
|
+
module.exports = function () { /* ... */ }
|
|
224
230
|
|
|
225
|
-
exports.hello =
|
|
231
|
+
exports.hello = 'world'
|
|
226
232
|
```
|
|
227
233
|
|
|
228
|
-
```
|
|
229
|
-
export default ...
|
|
234
|
+
```ts [After]
|
|
235
|
+
export default function () { /* ... */ }
|
|
230
236
|
|
|
231
|
-
export const hello =
|
|
237
|
+
export const hello = 'world'
|
|
232
238
|
```
|
|
233
239
|
|
|
234
240
|
::
|
|
@@ -242,7 +248,7 @@ const myLib = require('my-lib')
|
|
|
242
248
|
```js [After]
|
|
243
249
|
import myLib from 'my-lib'
|
|
244
250
|
// or
|
|
245
|
-
const
|
|
251
|
+
const dynamicMyLib = await import('my-lib').then(lib => lib.default || lib)
|
|
246
252
|
```
|
|
247
253
|
|
|
248
254
|
::
|
|
@@ -253,7 +259,7 @@ and should be replaced with `import()` and `import.meta.filename`.
|
|
|
253
259
|
::code-group
|
|
254
260
|
|
|
255
261
|
```js [Before]
|
|
256
|
-
|
|
262
|
+
const { join } = require('node:path')
|
|
257
263
|
|
|
258
264
|
const newDir = join(__dirname, 'new-dir')
|
|
259
265
|
```
|
|
@@ -282,7 +288,7 @@ const someFile = await resolvePath('my-lib', { url: import.meta.url })
|
|
|
282
288
|
|
|
283
289
|
### Best Practices
|
|
284
290
|
|
|
285
|
-
- Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](#default-exports) section)
|
|
291
|
+
- Prefer named exports rather than default export. This helps reduce CJS conflicts. (see [Default exports](/docs/4.x/guide/concepts/esm#default-exports) section)
|
|
286
292
|
|
|
287
293
|
- Avoid depending on Node.js built-ins and CommonJS or Node.js-only dependencies as much as possible to make your library usable in Browsers and Edge Workers without needing Nitro polyfills.
|
|
288
294
|
|
|
@@ -5,7 +5,7 @@ description: "Nuxt is fully typed and provides helpful shortcuts to ensure you h
|
|
|
5
5
|
|
|
6
6
|
## Type-checking
|
|
7
7
|
|
|
8
|
-
By default, Nuxt doesn't check types when you run [`nuxt dev`](/docs/api/commands/dev) or [`nuxt build`](/docs/api/commands/build), for performance reasons.
|
|
8
|
+
By default, Nuxt doesn't check types when you run [`nuxt dev`](/docs/4.x/api/commands/dev) or [`nuxt build`](/docs/4.x/api/commands/build), for performance reasons.
|
|
9
9
|
|
|
10
10
|
To enable type-checking at build or development time, install `vue-tsc` and `typescript` as development dependency:
|
|
11
11
|
|
|
@@ -29,19 +29,19 @@ To enable type-checking at build or development time, install `vue-tsc` and `typ
|
|
|
29
29
|
|
|
30
30
|
::
|
|
31
31
|
|
|
32
|
-
Then, run [`nuxt typecheck`](/docs/api/commands/typecheck) command to check your types:
|
|
32
|
+
Then, run [`nuxt typecheck`](/docs/4.x/api/commands/typecheck) command to check your types:
|
|
33
33
|
|
|
34
34
|
```bash [Terminal]
|
|
35
35
|
npx nuxt typecheck
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
To enable type-checking at build or development time, you can also use the [`typescript.typeCheck`](/docs/api/nuxt-config#typecheck) option in your `nuxt.config` file:
|
|
38
|
+
To enable type-checking at build or development time, you can also use the [`typescript.typeCheck`](/docs/4.x/api/nuxt-config#typecheck) option in your `nuxt.config` file:
|
|
39
39
|
|
|
40
40
|
```ts twoslash [nuxt.config.ts]
|
|
41
41
|
export default defineNuxtConfig({
|
|
42
42
|
typescript: {
|
|
43
|
-
typeCheck: true
|
|
44
|
-
}
|
|
43
|
+
typeCheck: true,
|
|
44
|
+
},
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -60,25 +60,25 @@ Some of the references in the file are to files that are only generated within y
|
|
|
60
60
|
This file contains the recommended basic TypeScript configuration for your project, including resolved aliases injected by Nuxt or modules you are using, so you can get full type support and path auto-complete for aliases like `~/file` or `#build/file`.
|
|
61
61
|
|
|
62
62
|
::note
|
|
63
|
-
Consider using the `imports` section of [nuxt.config](/docs/api/nuxt-config#imports) to include directories beyond the default ones. This can be useful for auto-importing types which you're using across your app.
|
|
63
|
+
Consider using the `imports` section of [nuxt.config](/docs/4.x/api/nuxt-config#imports) to include directories beyond the default ones. This can be useful for auto-importing types which you're using across your app.
|
|
64
64
|
::
|
|
65
65
|
|
|
66
|
-
[Read more about how to extend this configuration](/docs/guide/directory-structure/tsconfig).
|
|
66
|
+
[Read more about how to extend this configuration](/docs/4.x/guide/directory-structure/tsconfig).
|
|
67
67
|
|
|
68
68
|
::tip{icon="i-lucide-video" to="https://youtu.be/umLI7SlPygY" target="_blank"}
|
|
69
69
|
Watch a video from Daniel Roe explaining built-in Nuxt aliases.
|
|
70
70
|
::
|
|
71
71
|
|
|
72
72
|
::note
|
|
73
|
-
Nitro also [auto-generates types](/docs/guide/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/guide/directory-structure/app/composables), plus other core functionality.
|
|
73
|
+
Nitro also [auto-generates types](/docs/4.x/guide/concepts/server-engine#typed-api-routes) for API routes. Plus, Nuxt also generates types for globally available components and [auto-imports from your composables](/docs/4.x/guide/directory-structure/app/composables), plus other core functionality.
|
|
74
74
|
::
|
|
75
75
|
|
|
76
76
|
::note
|
|
77
|
-
For backward compatibility, Nuxt still generates `./.nuxt/tsconfig.json`. However, we recommend using [TypeScript project references](/docs/guide/directory-structure/tsconfig) with the new configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, etc.) for better type safety and performance.
|
|
77
|
+
For backward compatibility, Nuxt still generates `./.nuxt/tsconfig.json`. However, we recommend using [TypeScript project references](/docs/4.x/guide/directory-structure/tsconfig) with the new configuration files (`.nuxt/tsconfig.app.json`, `.nuxt/tsconfig.server.json`, etc.) for better type safety and performance.
|
|
78
78
|
|
|
79
79
|
If you do extend from `./.nuxt/tsconfig.json`, keep in mind that all options will be overwritten by those 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, which can cause module resolutions such as `#imports` to not be recognized.
|
|
80
80
|
|
|
81
|
-
In case you need to extend options further, you can use the [`alias` property](/docs/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend the generated TypeScript configurations accordingly.
|
|
81
|
+
In case you need to extend options further, you can use the [`alias` property](/docs/4.x/api/nuxt-config#alias) within your `nuxt.config`. Nuxt will pick them up and extend the generated TypeScript configurations accordingly.
|
|
82
82
|
::
|
|
83
83
|
|
|
84
84
|
## Project References
|
|
@@ -133,7 +133,7 @@ If you are currently converting your codebase to TypeScript, you may want to tem
|
|
|
133
133
|
```ts twoslash [nuxt.config.ts]
|
|
134
134
|
export default defineNuxtConfig({
|
|
135
135
|
typescript: {
|
|
136
|
-
strict: false
|
|
137
|
-
}
|
|
136
|
+
strict: false,
|
|
137
|
+
},
|
|
138
138
|
})
|
|
139
139
|
```
|
|
@@ -16,7 +16,7 @@ You can create your own custom events using the `hook` method:
|
|
|
16
16
|
```ts
|
|
17
17
|
const nuxtApp = useNuxtApp()
|
|
18
18
|
|
|
19
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
19
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
20
20
|
console.log('A new user has registered!', payload)
|
|
21
21
|
})
|
|
22
22
|
```
|
|
@@ -37,7 +37,7 @@ You can also use the payload object to enable two-way communication between the
|
|
|
37
37
|
```ts
|
|
38
38
|
const nuxtApp = useNuxtApp()
|
|
39
39
|
|
|
40
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
40
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
41
41
|
payload.message = 'Welcome to our app!'
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -58,6 +58,6 @@ await nuxtApp.callHook('app:user:registered', {
|
|
|
58
58
|
You can inspect all events using the **Nuxt DevTools** Hooks panel.
|
|
59
59
|
::
|
|
60
60
|
|
|
61
|
-
::read-more{to="/docs/guide/going-further/hooks"}
|
|
61
|
+
::read-more{to="/docs/4.x/guide/going-further/hooks"}
|
|
62
62
|
Learn more about Nuxt's built-in hooks and how to extend them
|
|
63
63
|
::
|