@nuxt/docs 0.0.0 → 3.17.1
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/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
package/.navigation.yml
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Introduction
|
|
3
|
+
description: Nuxt's goal is to make web development intuitive and performant with a great Developer Experience in mind.
|
|
4
|
+
navigation:
|
|
5
|
+
icon: i-lucide-info
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Nuxt is a free and [open-source framework](https://github.com/nuxt/nuxt) with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with [Vue.js](https://vuejs.org).
|
|
9
|
+
|
|
10
|
+
We made everything so you can start writing `.vue` files from the beginning while enjoying hot module replacement in development and a performant application in production with server-side rendering by default.
|
|
11
|
+
|
|
12
|
+
Nuxt has no vendor lock-in, allowing you to deploy your application [**everywhere, even on the edge**](/blog/nuxt-on-the-edge).
|
|
13
|
+
|
|
14
|
+
::tip
|
|
15
|
+
If you want to play around with Nuxt in your browser, you can [try it out in one of our online sandboxes](/docs/getting-started/installation#play-online).
|
|
16
|
+
::
|
|
17
|
+
|
|
18
|
+
## Automation and Conventions
|
|
19
|
+
|
|
20
|
+
Nuxt uses conventions and an opinionated directory structure to automate repetitive tasks and allow developers to focus on pushing features. The configuration file can still customize and override its default behaviors.
|
|
21
|
+
|
|
22
|
+
- **File-based routing:** define routes based on the structure of your [`pages/` directory](/docs/guide/directory-structure/pages). This can make it easier to organize your application and avoid the need for manual route configuration.
|
|
23
|
+
- **Code splitting:** Nuxt automatically splits your code into smaller chunks, which can help reduce the initial load time of your application.
|
|
24
|
+
- **Server-side rendering out of the box:** Nuxt comes with built-in SSR capabilities, so you don't have to set up a separate server yourself.
|
|
25
|
+
- **Auto-imports:** write Vue composables and components in their respective directories and use them without having to import them with the benefits of tree-shaking and optimized JS bundles.
|
|
26
|
+
- **Data-fetching utilities:** Nuxt provides composables to handle SSR-compatible data fetching as well as different strategies.
|
|
27
|
+
- **Zero-config TypeScript support:** write type-safe code without having to learn TypeScript with our auto-generated types and `tsconfig.json`
|
|
28
|
+
- **Configured build tools:** we use [Vite](https://vite.dev) by default to support hot module replacement (HMR) in development and bundling your code for production with best-practices baked-in.
|
|
29
|
+
|
|
30
|
+
Nuxt takes care of these and provides both frontend and backend functionality so you can focus on what matters: **creating your web application**.
|
|
31
|
+
|
|
32
|
+
## Server-Side Rendering
|
|
33
|
+
|
|
34
|
+
Nuxt comes with built-in server-side rendering (SSR) capabilities by default, without having to configure a server yourself, which has many benefits for web applications:
|
|
35
|
+
|
|
36
|
+
- **Faster initial page load time:** Nuxt sends a fully rendered HTML page to the browser, which can be displayed immediately. This can provide a faster perceived page load time and a better user experience (UX), especially on slower networks or devices.
|
|
37
|
+
- **Improved SEO:** search engines can better index SSR pages because the HTML content is available immediately, rather than requiring JavaScript to render the content on the client-side.
|
|
38
|
+
- **Better performance on low-powered devices:** it reduces the amount of JavaScript that needs to be downloaded and executed on the client-side, which can be beneficial for low-powered devices that may struggle with processing heavy JavaScript applications.
|
|
39
|
+
- **Better accessibility:** the content is immediately available on the initial page load, improving accessibility for users who rely on screen readers or other assistive technologies.
|
|
40
|
+
- **Easier caching:** pages can be cached on the server-side, which can further improve performance by reducing the amount of time it takes to generate and send the content to the client.
|
|
41
|
+
|
|
42
|
+
Overall, server-side rendering can provide a faster and more efficient user experience, as well as improve search engine optimization and accessibility.
|
|
43
|
+
|
|
44
|
+
As Nuxt is a versatile framework, it gives you the possibility to statically render your whole application to a static hosting with `nuxt generate`,
|
|
45
|
+
disable SSR globally with the `ssr: false` option or leverage hybrid rendering by setting up the `routeRules` option.
|
|
46
|
+
|
|
47
|
+
:read-more{title="Nuxt rendering modes" to="/docs/guide/concepts/rendering"}
|
|
48
|
+
|
|
49
|
+
### Server engine
|
|
50
|
+
|
|
51
|
+
The Nuxt server engine [Nitro](https://nitro.unjs.io) unlocks new full-stack capabilities.
|
|
52
|
+
|
|
53
|
+
In development, it uses Rollup and Node.js workers for your server code and context isolation. It also generates your server API by reading files in `server/api/` and server middleware from `server/middleware/`.
|
|
54
|
+
|
|
55
|
+
In production, Nitro builds your app and server into one universal `.output` directory. This output is light: minified and removed from any Node.js modules (except polyfills). You can deploy this output on any system supporting JavaScript, from Node.js, Serverless, Workers, Edge-side rendering or purely static.
|
|
56
|
+
|
|
57
|
+
:read-more{title="Nuxt server engine" to="/docs/guide/concepts/server-engine"}
|
|
58
|
+
|
|
59
|
+
### Production-ready
|
|
60
|
+
|
|
61
|
+
A Nuxt application can be deployed on a Node or Deno server, pre-rendered to be hosted in static environments, or deployed to serverless and edge providers.
|
|
62
|
+
|
|
63
|
+
:read-more{title="Deployment section" to="/docs/getting-started/deployment"}
|
|
64
|
+
|
|
65
|
+
### Modular
|
|
66
|
+
|
|
67
|
+
A module system allows to extend Nuxt with custom features and integrations with third-party services.
|
|
68
|
+
|
|
69
|
+
:read-more{title="Nuxt Modules Concept" to="/docs/guide/concepts/modules"}
|
|
70
|
+
|
|
71
|
+
### Architecture
|
|
72
|
+
|
|
73
|
+
Nuxt is composed of different [core packages](https://github.com/nuxt/nuxt/tree/main/packages):
|
|
74
|
+
|
|
75
|
+
- Core Engine: [nuxt](https://github.com/nuxt/nuxt/tree/main/packages/nuxt)
|
|
76
|
+
- Bundlers: [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite) and [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)
|
|
77
|
+
- Command line interface: [nuxi](https://github.com/nuxt/nuxt/tree/main/packages/nuxi)
|
|
78
|
+
- Server engine: [nitro](https://github.com/nitrojs/nitro)
|
|
79
|
+
- Development kit: [@nuxt/kit](https://github.com/nuxt/nuxt/tree/main/packages/kit)
|
|
80
|
+
|
|
81
|
+
We recommend reading each concept to have a full vision of Nuxt capabilities and the scope of each package.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Installation'
|
|
3
|
+
description: 'Get started with Nuxt quickly with our online starters or start locally with your terminal.'
|
|
4
|
+
navigation.icon: i-lucide-play
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Play Online
|
|
8
|
+
|
|
9
|
+
If you just want to play around with Nuxt in your browser without setting up a project, you can use one of our online sandboxes:
|
|
10
|
+
|
|
11
|
+
::card-group
|
|
12
|
+
:card{title="Open on StackBlitz" icon="i-simple-icons-stackblitz" to="https://nuxt.new/s/v3" target="_blank"}
|
|
13
|
+
:card{title="Open on CodeSandbox" icon="i-simple-icons-codesandbox" to="https://nuxt.new/c/v3" target="_blank"}
|
|
14
|
+
::
|
|
15
|
+
|
|
16
|
+
Or follow the steps below to set up a new Nuxt project on your computer.
|
|
17
|
+
|
|
18
|
+
## New Project
|
|
19
|
+
|
|
20
|
+
<!-- TODO: need to fix upstream in nuxt/nuxt.com -->
|
|
21
|
+
<!-- markdownlint-disable-next-line MD001 -->
|
|
22
|
+
#### Prerequisites
|
|
23
|
+
|
|
24
|
+
- **Node.js** - [`18.x`](https://nodejs.org/en) or newer (but we recommend the [active LTS release](https://github.com/nodejs/release#release-schedule))
|
|
25
|
+
- **Text editor** - There is no IDE requirement, but we recommend [Visual Studio Code](https://code.visualstudio.com/) with the [official Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (previously known as Volar) or [WebStorm](https://www.jetbrains.com/webstorm/), which, along with [other JetBrains IDEs](https://www.jetbrains.com/ides/), offers great Nuxt support right out-of-the-box.
|
|
26
|
+
- **Terminal** - In order to run Nuxt commands
|
|
27
|
+
|
|
28
|
+
::note
|
|
29
|
+
::details
|
|
30
|
+
:summary[Additional notes for an optimal setup:]
|
|
31
|
+
- **Node.js**: Make sure to use an even numbered version (18, 20, etc)
|
|
32
|
+
- **Nuxtr**: Install the community-developed [Nuxtr extension](https://marketplace.visualstudio.com/items?itemName=Nuxtr.nuxtr-vscode)
|
|
33
|
+
- **WSL**: If you are using Windows and experience slow HMR, you may want to try using [WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/install) which may solve some performance issues.
|
|
34
|
+
::
|
|
35
|
+
::
|
|
36
|
+
|
|
37
|
+
Open a terminal (if you're using [Visual Studio Code](https://code.visualstudio.com), you can open an [integrated terminal](https://code.visualstudio.com/docs/editor/integrated-terminal)) and use the following command to create a new starter project:
|
|
38
|
+
|
|
39
|
+
::code-group{sync="pm"}
|
|
40
|
+
|
|
41
|
+
```bash [npm]
|
|
42
|
+
npm create nuxt <project-name>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```bash [yarn]
|
|
46
|
+
yarn create nuxt <project-name>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```bash [pnpm]
|
|
50
|
+
pnpm create nuxt <project-name>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```bash [bun]
|
|
54
|
+
bun create nuxt <project-name>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
::
|
|
58
|
+
|
|
59
|
+
::tip
|
|
60
|
+
Alternatively, you can find other starters or themes by opening [nuxt.new](https://nuxt.new) and following the instructions there.
|
|
61
|
+
::
|
|
62
|
+
|
|
63
|
+
Open your project folder in Visual Studio Code:
|
|
64
|
+
|
|
65
|
+
```bash [Terminal]
|
|
66
|
+
code <project-name>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or change directory into your new project from your terminal:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cd <project-name>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Development Server
|
|
76
|
+
|
|
77
|
+
Now you'll be able to start your Nuxt app in development mode:
|
|
78
|
+
|
|
79
|
+
::code-group{sync="pm"}
|
|
80
|
+
|
|
81
|
+
```bash [npm]
|
|
82
|
+
npm run dev -- -o
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash [yarn]
|
|
86
|
+
yarn dev --open
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```bash [pnpm]
|
|
90
|
+
pnpm dev -o
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```bash [bun]
|
|
94
|
+
bun run dev -o
|
|
95
|
+
|
|
96
|
+
# To use the Bun runtime during development
|
|
97
|
+
# bun --bun run dev -o
|
|
98
|
+
```
|
|
99
|
+
::
|
|
100
|
+
|
|
101
|
+
::tip{icon="i-lucide-circle-check"}
|
|
102
|
+
Well done! A browser window should automatically open for <http://localhost:3000>.
|
|
103
|
+
::
|
|
104
|
+
|
|
105
|
+
## Next Steps
|
|
106
|
+
|
|
107
|
+
Now that you've created your Nuxt project, you are ready to start building your application.
|
|
108
|
+
|
|
109
|
+
:read-more{title="Nuxt Concepts" to="/docs/guide/concepts"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Configuration
|
|
3
|
+
description: Nuxt is configured with sensible defaults to make you productive.
|
|
4
|
+
navigation.icon: i-lucide-cog
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
By default, Nuxt is configured to cover most use cases. The [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file can override or extend this default configuration.
|
|
8
|
+
|
|
9
|
+
## Nuxt Configuration
|
|
10
|
+
|
|
11
|
+
The [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file is located at the root of a Nuxt project and can override or extend the application's behavior.
|
|
12
|
+
|
|
13
|
+
A minimal configuration file exports the `defineNuxtConfig` function containing an object with your configuration. The `defineNuxtConfig` helper is globally available without import.
|
|
14
|
+
|
|
15
|
+
```ts twoslash [nuxt.config.ts]
|
|
16
|
+
export default defineNuxtConfig({
|
|
17
|
+
// My Nuxt config
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This file will often be mentioned in the documentation, for example to add custom scripts, register modules or change rendering modes.
|
|
22
|
+
|
|
23
|
+
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
24
|
+
Every option is described in the **Configuration Reference**.
|
|
25
|
+
::
|
|
26
|
+
|
|
27
|
+
::note
|
|
28
|
+
You don't have to use TypeScript to build an application with Nuxt. However, it is strongly recommended to use the `.ts` extension for the `nuxt.config` file. This way you can benefit from hints in your IDE to avoid typos and mistakes while editing your configuration.
|
|
29
|
+
::
|
|
30
|
+
|
|
31
|
+
### Environment Overrides
|
|
32
|
+
|
|
33
|
+
You can configure fully typed, per-environment overrides in your nuxt.config
|
|
34
|
+
|
|
35
|
+
```ts twoslash [nuxt.config.ts]
|
|
36
|
+
export default defineNuxtConfig({
|
|
37
|
+
$production: {
|
|
38
|
+
routeRules: {
|
|
39
|
+
'/**': { isr: true }
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
$development: {
|
|
43
|
+
//
|
|
44
|
+
},
|
|
45
|
+
$env: {
|
|
46
|
+
staging: {
|
|
47
|
+
//
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To select an environment when running a Nuxt CLI command, simply pass the name to the `--envName` flag, like so: `nuxi build --envName staging`.
|
|
54
|
+
|
|
55
|
+
To learn more about the mechanism behind these overrides, please refer to the `c12` documentation on [environment-specific configuration](https://github.com/unjs/c12?tab=readme-ov-file#environment-specific-configuration).
|
|
56
|
+
|
|
57
|
+
:video-accordion{title="Watch a video from Alexander Lichter about the env-aware nuxt.config.ts" videoId="DFZI2iVCrNc"}
|
|
58
|
+
|
|
59
|
+
::note
|
|
60
|
+
If you're authoring layers, you can also use the `$meta` key to provide metadata that you or the consumers of your layer might use.
|
|
61
|
+
::
|
|
62
|
+
|
|
63
|
+
### Environment Variables and Private Tokens
|
|
64
|
+
|
|
65
|
+
The `runtimeConfig` API exposes values like environment variables to the rest of your application. By default, these keys are only available server-side. The keys within `runtimeConfig.public` and `runtimeConfig.app` (which is used by Nuxt internally) are also available client-side.
|
|
66
|
+
|
|
67
|
+
Those values should be defined in `nuxt.config` and can be overridden using environment variables.
|
|
68
|
+
|
|
69
|
+
::code-group
|
|
70
|
+
|
|
71
|
+
```ts twoslash [nuxt.config.ts]
|
|
72
|
+
export default defineNuxtConfig({
|
|
73
|
+
runtimeConfig: {
|
|
74
|
+
// The private keys which are only available server-side
|
|
75
|
+
apiSecret: '123',
|
|
76
|
+
// Keys within public are also exposed client-side
|
|
77
|
+
public: {
|
|
78
|
+
apiBase: '/api'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```ini [.env]
|
|
85
|
+
# This will override the value of apiSecret
|
|
86
|
+
NUXT_API_SECRET=api_secret_token
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
::
|
|
90
|
+
|
|
91
|
+
These variables are exposed to the rest of your application using the [`useRuntimeConfig()`](/docs/api/composables/use-runtime-config) composable.
|
|
92
|
+
|
|
93
|
+
```vue [pages/index.vue]
|
|
94
|
+
<script setup lang="ts">
|
|
95
|
+
const runtimeConfig = useRuntimeConfig()
|
|
96
|
+
</script>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
100
|
+
|
|
101
|
+
## App Configuration
|
|
102
|
+
|
|
103
|
+
The `app.config.ts` file, located in the source directory (by default the root of the project), is used to expose public variables that can be determined at build time. Contrary to the `runtimeConfig` option, these can not be overridden using environment variables.
|
|
104
|
+
|
|
105
|
+
A minimal configuration file exports the `defineAppConfig` function containing an object with your configuration. The `defineAppConfig` helper is globally available without import.
|
|
106
|
+
|
|
107
|
+
```ts [app.config.ts]
|
|
108
|
+
export default defineAppConfig({
|
|
109
|
+
title: 'Hello Nuxt',
|
|
110
|
+
theme: {
|
|
111
|
+
dark: true,
|
|
112
|
+
colors: {
|
|
113
|
+
primary: '#ff0000'
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
These variables are exposed to the rest of your application using the [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
120
|
+
|
|
121
|
+
```vue [pages/index.vue]
|
|
122
|
+
<script setup lang="ts">
|
|
123
|
+
const appConfig = useAppConfig()
|
|
124
|
+
</script>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
:read-more{to="/docs/guide/directory-structure/app-config"}
|
|
128
|
+
|
|
129
|
+
## `runtimeConfig` vs. `app.config`
|
|
130
|
+
|
|
131
|
+
As stated above, `runtimeConfig` and `app.config` are both used to expose variables to the rest of your application. To determine whether you should use one or the other, here are some guidelines:
|
|
132
|
+
|
|
133
|
+
- `runtimeConfig`: Private or public tokens that need to be specified after build using environment variables.
|
|
134
|
+
- `app.config`: Public tokens that are determined at build time, website configuration such as theme variant, title and any project config that are not sensitive.
|
|
135
|
+
|
|
136
|
+
Feature | `runtimeConfig` | `app.config`
|
|
137
|
+
-------------------------------|------------------|-------------------
|
|
138
|
+
Client Side | Hydrated | Bundled
|
|
139
|
+
Environment Variables | ✅ Yes | ❌ No
|
|
140
|
+
Reactive | ✅ Yes | ✅ Yes
|
|
141
|
+
Types support | ✅ Partial | ✅ Yes
|
|
142
|
+
Configuration per Request | ❌ No | ✅ Yes
|
|
143
|
+
Hot Module Replacement | ❌ No | ✅ Yes
|
|
144
|
+
Non primitive JS types | ❌ No | ✅ Yes
|
|
145
|
+
|
|
146
|
+
## External Configuration Files
|
|
147
|
+
|
|
148
|
+
Nuxt uses [`nuxt.config.ts`](/docs/guide/directory-structure/nuxt-config) file as the single source of truth for configurations and skips reading external configuration files. During the course of building your project, you may have a need to configure those. The following table highlights common configurations and, where applicable, how they can be configured with Nuxt.
|
|
149
|
+
|
|
150
|
+
Name | Config File | How To Configure
|
|
151
|
+
---------------------------------------------|---------------------------|-------------------------
|
|
152
|
+
[Nitro](https://nitro.unjs.io) | ~~`nitro.config.ts`~~ | Use [`nitro`](/docs/api/nuxt-config#nitro) key in `nuxt.config`
|
|
153
|
+
[PostCSS](https://postcss.org) | ~~`postcss.config.js`~~ | Use [`postcss`](/docs/api/nuxt-config#postcss) key in `nuxt.config`
|
|
154
|
+
[Vite](https://vite.dev) | ~~`vite.config.ts`~~ | Use [`vite`](/docs/api/nuxt-config#vite) key in `nuxt.config`
|
|
155
|
+
[webpack](https://webpack.js.org) | ~~`webpack.config.ts`~~ | Use [`webpack`](/docs/api/nuxt-config#webpack-1) key in `nuxt.config`
|
|
156
|
+
|
|
157
|
+
Here is a list of other common config files:
|
|
158
|
+
|
|
159
|
+
Name | Config File | How To Configure
|
|
160
|
+
---------------------------------------------|-------------------------|--------------------------
|
|
161
|
+
[TypeScript](https://www.typescriptlang.org) | `tsconfig.json` | [More Info](/docs/guide/concepts/typescript#nuxttsconfigjson)
|
|
162
|
+
[ESLint](https://eslint.org) | `eslint.config.js` | [More Info](https://eslint.org/docs/latest/use/configure/configuration-files)
|
|
163
|
+
[Prettier](https://prettier.io) | `prettier.config.js` | [More Info](https://prettier.io/docs/en/configuration.html)
|
|
164
|
+
[Stylelint](https://stylelint.io) | `stylelint.config.js` | [More Info](https://stylelint.io/user-guide/configure)
|
|
165
|
+
[TailwindCSS](https://tailwindcss.com) | `tailwind.config.js` | [More Info](https://tailwindcss.nuxtjs.org/tailwindcss/configuration)
|
|
166
|
+
[Vitest](https://vitest.dev) | `vitest.config.ts` | [More Info](https://vitest.dev/config/)
|
|
167
|
+
|
|
168
|
+
## Vue Configuration
|
|
169
|
+
|
|
170
|
+
### With Vite
|
|
171
|
+
|
|
172
|
+
If you need to pass options to `@vitejs/plugin-vue` or `@vitejs/plugin-vue-jsx`, you can do this in your `nuxt.config` file.
|
|
173
|
+
|
|
174
|
+
- `vite.vue` for `@vitejs/plugin-vue`. Check available options [here](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue).
|
|
175
|
+
- `vite.vueJsx` for `@vitejs/plugin-vue-jsx`. Check available options [here](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx).
|
|
176
|
+
|
|
177
|
+
```ts twoslash [nuxt.config.ts]
|
|
178
|
+
export default defineNuxtConfig({
|
|
179
|
+
vite: {
|
|
180
|
+
vue: {
|
|
181
|
+
customElement: true
|
|
182
|
+
},
|
|
183
|
+
vueJsx: {
|
|
184
|
+
mergeProps: true
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
:read-more{to="/docs/api/configuration/nuxt-config#vue"}
|
|
191
|
+
|
|
192
|
+
### With webpack
|
|
193
|
+
|
|
194
|
+
If you use webpack and need to configure `vue-loader`, you can do this using `webpack.loaders.vue` key inside your `nuxt.config` file. The available options are [defined here](https://github.com/vuejs/vue-loader/blob/main/src/index.ts#L32-L62).
|
|
195
|
+
|
|
196
|
+
```ts twoslash [nuxt.config.ts]
|
|
197
|
+
export default defineNuxtConfig({
|
|
198
|
+
webpack: {
|
|
199
|
+
loaders: {
|
|
200
|
+
vue: {
|
|
201
|
+
hotReload: true,
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
:read-more{to="/docs/api/configuration/nuxt-config#loaders"}
|
|
209
|
+
|
|
210
|
+
### Enabling Experimental Vue Features
|
|
211
|
+
|
|
212
|
+
You may need to enable experimental features in Vue, such as `propsDestructure`. Nuxt provides an easy way to do that in `nuxt.config.ts`, no matter which builder you are using:
|
|
213
|
+
|
|
214
|
+
```ts twoslash [nuxt.config.ts]
|
|
215
|
+
export default defineNuxtConfig({
|
|
216
|
+
vue: {
|
|
217
|
+
propsDestructure: true
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### experimental `reactivityTransform` migration from Vue 3.4 and Nuxt 3.9
|
|
223
|
+
|
|
224
|
+
Since Nuxt 3.9 and Vue 3.4, `reactivityTransform` has been moved from Vue to Vue Macros which has a [Nuxt integration](https://vue-macros.dev/guide/nuxt-integration.html).
|
|
225
|
+
|
|
226
|
+
:read-more{to="/docs/api/configuration/nuxt-config#vue-1"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Views'
|
|
3
|
+
description: 'Nuxt provides several component layers to implement the user interface of your application.'
|
|
4
|
+
navigation.icon: i-lucide-panels-top-left
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## `app.vue`
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
By default, Nuxt will treat this file as the **entrypoint** and render its content for every route of the application.
|
|
12
|
+
|
|
13
|
+
```vue [app.vue]
|
|
14
|
+
<template>
|
|
15
|
+
<div>
|
|
16
|
+
<h1>Welcome to the homepage</h1>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
::tip
|
|
22
|
+
If you are familiar with Vue, you might wonder where `main.js` is (the file that normally creates a Vue app). Nuxt does this behind the scene.
|
|
23
|
+
::
|
|
24
|
+
|
|
25
|
+
## Components
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
Most components are reusable pieces of the user interface, like buttons and menus. In Nuxt, you can create these components in the [`components/`](/docs/guide/directory-structure/components) directory, and they will be automatically available across your application without having to explicitly import them.
|
|
30
|
+
|
|
31
|
+
::code-group
|
|
32
|
+
|
|
33
|
+
```vue [app.vue]
|
|
34
|
+
<template>
|
|
35
|
+
<div>
|
|
36
|
+
<h1>Welcome to the homepage</h1>
|
|
37
|
+
<AppAlert>
|
|
38
|
+
This is an auto-imported component.
|
|
39
|
+
</AppAlert>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```vue [components/AppAlert.vue]
|
|
45
|
+
<template>
|
|
46
|
+
<span>
|
|
47
|
+
<slot />
|
|
48
|
+
</span>
|
|
49
|
+
</template>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
::
|
|
53
|
+
|
|
54
|
+
## Pages
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
Pages represent views for each specific route pattern. Every file in the [`pages/`](/docs/guide/directory-structure/pages) directory represents a different route displaying its content.
|
|
59
|
+
|
|
60
|
+
To use pages, create `pages/index.vue` file and add `<NuxtPage />` component to the [`app.vue`](/docs/guide/directory-structure/app) (or remove `app.vue` for default entry). You can now create more pages and their corresponding routes by adding new files in the [`pages/`](/docs/guide/directory-structure/pages) directory.
|
|
61
|
+
|
|
62
|
+
::code-group
|
|
63
|
+
|
|
64
|
+
```vue [pages/index.vue]
|
|
65
|
+
<template>
|
|
66
|
+
<div>
|
|
67
|
+
<h1>Welcome to the homepage</h1>
|
|
68
|
+
<AppAlert>
|
|
69
|
+
This is an auto-imported component
|
|
70
|
+
</AppAlert>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```vue [pages/about.vue]
|
|
76
|
+
<template>
|
|
77
|
+
<section>
|
|
78
|
+
<p>This page will be displayed at the /about route.</p>
|
|
79
|
+
</section>
|
|
80
|
+
</template>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
::
|
|
84
|
+
|
|
85
|
+
:read-more{title="Routing Section" to="/docs/getting-started/routing"}
|
|
86
|
+
|
|
87
|
+
## Layouts
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
Layouts are wrappers around pages that contain a common User Interface for several pages, such as a header and footer display. Layouts are Vue files using `<slot />` components to display the **page** content. The `layouts/default.vue` file will be used by default. Custom layouts can be set as part of your page metadata.
|
|
92
|
+
|
|
93
|
+
::note
|
|
94
|
+
If you only have a single layout in your application, we recommend using [`app.vue`](/docs/guide/directory-structure/app) with [`<NuxtPage />`](/docs/api/components/nuxt-page) instead.
|
|
95
|
+
::
|
|
96
|
+
|
|
97
|
+
::code-group
|
|
98
|
+
|
|
99
|
+
```vue [app.vue]
|
|
100
|
+
<template>
|
|
101
|
+
<div>
|
|
102
|
+
<NuxtLayout>
|
|
103
|
+
<NuxtPage />
|
|
104
|
+
</NuxtLayout>
|
|
105
|
+
</div>
|
|
106
|
+
</template>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```vue [layouts/default.vue]
|
|
110
|
+
<template>
|
|
111
|
+
<div>
|
|
112
|
+
<AppHeader />
|
|
113
|
+
<slot />
|
|
114
|
+
<AppFooter />
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```vue [pages/index.vue]
|
|
120
|
+
<template>
|
|
121
|
+
<div>
|
|
122
|
+
<h1>Welcome to the homepage</h1>
|
|
123
|
+
<AppAlert>
|
|
124
|
+
This is an auto-imported component
|
|
125
|
+
</AppAlert>
|
|
126
|
+
</div>
|
|
127
|
+
</template>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```vue [pages/about.vue]
|
|
131
|
+
<template>
|
|
132
|
+
<section>
|
|
133
|
+
<p>This page will be displayed at the /about route.</p>
|
|
134
|
+
</section>
|
|
135
|
+
</template>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
::
|
|
139
|
+
|
|
140
|
+
If you want to create more layouts and learn how to use them in your pages, find more information in the [Layouts section](/docs/guide/directory-structure/layouts).
|
|
141
|
+
|
|
142
|
+
## Advanced: Extending the HTML Template
|
|
143
|
+
|
|
144
|
+
::note
|
|
145
|
+
If you only need to modify the `<head>`, you can refer to the [SEO and meta section](/docs/getting-started/seo-meta).
|
|
146
|
+
::
|
|
147
|
+
|
|
148
|
+
You can have full control over the HTML template by adding a Nitro plugin that registers a hook.
|
|
149
|
+
The callback function of the `render:html` hook allows you to mutate the HTML before it is sent to the client.
|
|
150
|
+
|
|
151
|
+
```ts twoslash [server/plugins/extend-html.ts]
|
|
152
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
153
|
+
nitroApp.hooks.hook('render:html', (html, { event }) => {
|
|
154
|
+
// This will be an object representation of the html template.
|
|
155
|
+
console.log(html)
|
|
156
|
+
html.head.push(`<meta name="description" content="My custom description" />`)
|
|
157
|
+
})
|
|
158
|
+
// You can also intercept the response here.
|
|
159
|
+
nitroApp.hooks.hook('render:response', (response, { event }) => { console.log(response) })
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
:read-more{to="/docs/guide/going-further/hooks"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'Assets'
|
|
3
|
+
description: 'Nuxt offers two options for your assets.'
|
|
4
|
+
navigation.icon: i-lucide-image
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Nuxt uses two directories to handle assets like stylesheets, fonts or images.
|
|
8
|
+
|
|
9
|
+
- The [`public/`](/docs/guide/directory-structure/public) directory content is served at the server root as-is.
|
|
10
|
+
- The [`assets/`](/docs/guide/directory-structure/assets) directory contains by convention every asset that you want the build tool (Vite or webpack) to process.
|
|
11
|
+
|
|
12
|
+
## Public Directory
|
|
13
|
+
|
|
14
|
+
The [`public/`](/docs/guide/directory-structure/public) directory is used as a public server for static assets publicly available at a defined URL of your application.
|
|
15
|
+
|
|
16
|
+
You can get a file in the [`public/`](/docs/guide/directory-structure/public) directory from your application's code or from a browser by the root URL `/`.
|
|
17
|
+
|
|
18
|
+
### Example
|
|
19
|
+
|
|
20
|
+
For example, referencing an image file in the `public/img/` directory, available at the static URL `/img/nuxt.png`:
|
|
21
|
+
|
|
22
|
+
```vue [app.vue]
|
|
23
|
+
<template>
|
|
24
|
+
<img src="/img/nuxt.png" alt="Discover Nuxt" />
|
|
25
|
+
</template>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Assets Directory
|
|
29
|
+
|
|
30
|
+
Nuxt uses [Vite](https://vite.dev/guide/assets.html) (default) or [webpack](https://webpack.js.org/guides/asset-management) to build and bundle your application. The main function of these build tools is to process JavaScript files, but they can be extended through [plugins](https://vite.dev/plugins) (for Vite) or [loaders](https://webpack.js.org/loaders) (for webpack) to process other kinds of assets, like stylesheets, fonts or SVGs. This step transforms the original file, mainly for performance or caching purposes (such as stylesheet minification or browser cache invalidation).
|
|
31
|
+
|
|
32
|
+
By convention, Nuxt uses the [`assets/`](/docs/guide/directory-structure/assets) directory to store these files but there is no auto-scan functionality for this directory, and you can use any other name for it.
|
|
33
|
+
|
|
34
|
+
In your application's code, you can reference a file located in the [`assets/`](/docs/guide/directory-structure/assets) directory by using the `~/assets/` path.
|
|
35
|
+
|
|
36
|
+
### Example
|
|
37
|
+
|
|
38
|
+
For example, referencing an image file that will be processed if a build tool is configured to handle this file extension:
|
|
39
|
+
|
|
40
|
+
```vue [app.vue]
|
|
41
|
+
<template>
|
|
42
|
+
<img src="~/assets/img/nuxt.png" alt="Discover Nuxt" />
|
|
43
|
+
</template>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
::note
|
|
47
|
+
Nuxt won't serve files in the [`assets/`](/docs/guide/directory-structure/assets) directory at a static URL like `/assets/my-file.png`. If you need a static URL, use the [`public/`](#public-directory) directory.
|
|
48
|
+
::
|