@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
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Builder
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with the builder. These functions allow you to extend the webpack and vite configurations.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/build.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt have builders based on [webpack](https://github.com/nuxt/nuxt/tree/main/packages/webpack) and [vite](https://github.com/nuxt/nuxt/tree/main/packages/vite). You can extend the config passed to each one using `extendWebpackConfig` and `extendViteConfig` functions. You can also add additional plugins via `addVitePlugin`, `addWebpackPlugin` and `addBuildPlugin`.
|
|
12
|
+
|
|
13
|
+
## `extendWebpackConfig`
|
|
14
|
+
|
|
15
|
+
Extends the webpack configuration. Callback function can be called multiple times, when applying to both client and server builds.
|
|
16
|
+
|
|
17
|
+
### Type
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
function extendWebpackConfig (callback: ((config: WebpackConfig) => void), options?: ExtendWebpackConfigOptions): void
|
|
21
|
+
|
|
22
|
+
export interface ExtendWebpackConfigOptions {
|
|
23
|
+
dev?: boolean
|
|
24
|
+
build?: boolean
|
|
25
|
+
server?: boolean
|
|
26
|
+
client?: boolean
|
|
27
|
+
prepend?: boolean
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
::read-more{to="https://webpack.js.org/configuration" target="_blank" icon="i-simple-icons-webpack"}
|
|
32
|
+
Checkout webpack website for more information about its configuration.
|
|
33
|
+
::
|
|
34
|
+
|
|
35
|
+
### Parameters
|
|
36
|
+
|
|
37
|
+
#### `callback`
|
|
38
|
+
|
|
39
|
+
**Type**: `(config: WebpackConfig) => void`
|
|
40
|
+
|
|
41
|
+
**Required**: `true`
|
|
42
|
+
|
|
43
|
+
A callback function that will be called with the webpack configuration object.
|
|
44
|
+
|
|
45
|
+
#### `options`
|
|
46
|
+
|
|
47
|
+
**Type**: `ExtendWebpackConfigOptions`
|
|
48
|
+
|
|
49
|
+
**Default**: `{}`
|
|
50
|
+
|
|
51
|
+
Options to pass to the callback function. This object can have the following properties:
|
|
52
|
+
|
|
53
|
+
- `dev` (optional)
|
|
54
|
+
|
|
55
|
+
**Type**: `boolean`
|
|
56
|
+
|
|
57
|
+
**Default**: `true`
|
|
58
|
+
|
|
59
|
+
If set to `true`, the callback function will be called when building in development mode.
|
|
60
|
+
|
|
61
|
+
- `build` (optional)
|
|
62
|
+
|
|
63
|
+
**Type**: `boolean`
|
|
64
|
+
|
|
65
|
+
**Default**: `true`
|
|
66
|
+
|
|
67
|
+
If set to `true`, the callback function will be called when building in production mode.
|
|
68
|
+
|
|
69
|
+
- `server` (optional)
|
|
70
|
+
|
|
71
|
+
**Type**: `boolean`
|
|
72
|
+
|
|
73
|
+
**Default**: `true`
|
|
74
|
+
|
|
75
|
+
If set to `true`, the callback function will be called when building the server bundle.
|
|
76
|
+
|
|
77
|
+
- `client` (optional)
|
|
78
|
+
|
|
79
|
+
**Type**: `boolean`
|
|
80
|
+
|
|
81
|
+
**Default**: `true`
|
|
82
|
+
|
|
83
|
+
If set to `true`, the callback function will be called when building the client bundle.
|
|
84
|
+
|
|
85
|
+
- `prepend` (optional)
|
|
86
|
+
|
|
87
|
+
**Type**: `boolean`
|
|
88
|
+
|
|
89
|
+
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
90
|
+
|
|
91
|
+
### Examples
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { defineNuxtModule, extendWebpackConfig } from '@nuxt/kit'
|
|
95
|
+
|
|
96
|
+
export default defineNuxtModule({
|
|
97
|
+
setup() {
|
|
98
|
+
extendWebpackConfig((config) => {
|
|
99
|
+
config.module?.rules.push({
|
|
100
|
+
test: /\.txt$/,
|
|
101
|
+
use: 'raw-loader'
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## `extendViteConfig`
|
|
109
|
+
|
|
110
|
+
Extends the Vite configuration. Callback function can be called multiple times, when applying to both client and server builds.
|
|
111
|
+
|
|
112
|
+
### Type
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
function extendViteConfig (callback: ((config: ViteConfig) => void), options?: ExtendViteConfigOptions): void
|
|
116
|
+
|
|
117
|
+
export interface ExtendViteConfigOptions {
|
|
118
|
+
dev?: boolean
|
|
119
|
+
build?: boolean
|
|
120
|
+
server?: boolean
|
|
121
|
+
client?: boolean
|
|
122
|
+
prepend?: boolean
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
::read-more{to="https://vite.dev/config" target="_blank" icon="i-simple-icons-vite"}
|
|
127
|
+
Checkout Vite website for more information about its configuration.
|
|
128
|
+
::
|
|
129
|
+
|
|
130
|
+
### Parameters
|
|
131
|
+
|
|
132
|
+
#### `callback`
|
|
133
|
+
|
|
134
|
+
**Type**: `(config: ViteConfig) => void`
|
|
135
|
+
|
|
136
|
+
**Required**: `true`
|
|
137
|
+
|
|
138
|
+
A callback function that will be called with the Vite configuration object.
|
|
139
|
+
|
|
140
|
+
#### `options`
|
|
141
|
+
|
|
142
|
+
**Type**: `ExtendViteConfigOptions`
|
|
143
|
+
|
|
144
|
+
**Default**: `{}`
|
|
145
|
+
|
|
146
|
+
Options to pass to the callback function. This object can have the following properties:
|
|
147
|
+
|
|
148
|
+
- `dev` (optional)
|
|
149
|
+
|
|
150
|
+
**Type**: `boolean`
|
|
151
|
+
|
|
152
|
+
**Default**: `true`
|
|
153
|
+
|
|
154
|
+
If set to `true`, the callback function will be called when building in development mode.
|
|
155
|
+
|
|
156
|
+
- `build` (optional)
|
|
157
|
+
|
|
158
|
+
**Type**: `boolean`
|
|
159
|
+
|
|
160
|
+
**Default**: `true`
|
|
161
|
+
|
|
162
|
+
If set to `true`, the callback function will be called when building in production mode.
|
|
163
|
+
|
|
164
|
+
- `server` (optional)
|
|
165
|
+
|
|
166
|
+
**Type**: `boolean`
|
|
167
|
+
|
|
168
|
+
**Default**: `true`
|
|
169
|
+
|
|
170
|
+
If set to `true`, the callback function will be called when building the server bundle.
|
|
171
|
+
|
|
172
|
+
- `client` (optional)
|
|
173
|
+
|
|
174
|
+
**Type**: `boolean`
|
|
175
|
+
|
|
176
|
+
**Default**: `true`
|
|
177
|
+
|
|
178
|
+
If set to `true`, the callback function will be called when building the client bundle.
|
|
179
|
+
|
|
180
|
+
- `prepend` (optional)
|
|
181
|
+
|
|
182
|
+
**Type**: `boolean`
|
|
183
|
+
|
|
184
|
+
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
185
|
+
|
|
186
|
+
### Examples
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
// https://github.com/Hrdtr/nuxt-appwrite
|
|
190
|
+
import { defineNuxtModule, extendViteConfig } from '@nuxt/kit'
|
|
191
|
+
|
|
192
|
+
export default defineNuxtModule({
|
|
193
|
+
setup() {
|
|
194
|
+
extendViteConfig((config) => {
|
|
195
|
+
config.optimizeDeps = config.optimizeDeps || {}
|
|
196
|
+
config.optimizeDeps.include = config.optimizeDeps.include || []
|
|
197
|
+
config.optimizeDeps.include.push('cross-fetch')
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## `addWebpackPlugin`
|
|
204
|
+
|
|
205
|
+
Append webpack plugin to the config.
|
|
206
|
+
|
|
207
|
+
### Type
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
function addWebpackPlugin (pluginOrGetter: PluginOrGetter, options?: ExtendWebpackConfigOptions): void
|
|
211
|
+
|
|
212
|
+
type PluginOrGetter = WebpackPluginInstance | WebpackPluginInstance[] | (() => WebpackPluginInstance | WebpackPluginInstance[])
|
|
213
|
+
|
|
214
|
+
interface ExtendWebpackConfigOptions {
|
|
215
|
+
dev?: boolean
|
|
216
|
+
build?: boolean
|
|
217
|
+
server?: boolean
|
|
218
|
+
client?: boolean
|
|
219
|
+
prepend?: boolean
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
::tip
|
|
224
|
+
See [webpack website](https://webpack.js.org/concepts/plugins) for more information about webpack plugins. You can also use [this collection](https://webpack.js.org/awesome-webpack/#webpack-plugins) to find a plugin that suits your needs.
|
|
225
|
+
::
|
|
226
|
+
|
|
227
|
+
### Parameters
|
|
228
|
+
|
|
229
|
+
#### `pluginOrGetter`
|
|
230
|
+
|
|
231
|
+
**Type**: `PluginOrGetter`
|
|
232
|
+
|
|
233
|
+
**Required**: `true`
|
|
234
|
+
|
|
235
|
+
A webpack plugin instance or an array of webpack plugin instances. If a function is provided, it must return a webpack plugin instance or an array of webpack plugin instances.
|
|
236
|
+
|
|
237
|
+
#### `options`
|
|
238
|
+
|
|
239
|
+
**Type**: `ExtendWebpackConfigOptions`
|
|
240
|
+
|
|
241
|
+
**Default**: `{}`
|
|
242
|
+
|
|
243
|
+
Options to pass to the callback function. This object can have the following properties:
|
|
244
|
+
|
|
245
|
+
- `dev` (optional)
|
|
246
|
+
|
|
247
|
+
**Type**: `boolean`
|
|
248
|
+
|
|
249
|
+
**Default**: `true`
|
|
250
|
+
|
|
251
|
+
If set to `true`, the callback function will be called when building in development mode.
|
|
252
|
+
|
|
253
|
+
- `build` (optional)
|
|
254
|
+
|
|
255
|
+
**Type**: `boolean`
|
|
256
|
+
|
|
257
|
+
**Default**: `true`
|
|
258
|
+
|
|
259
|
+
If set to `true`, the callback function will be called when building in production mode.
|
|
260
|
+
|
|
261
|
+
- `server` (optional)
|
|
262
|
+
|
|
263
|
+
**Type**: `boolean`
|
|
264
|
+
|
|
265
|
+
**Default**: `true`
|
|
266
|
+
|
|
267
|
+
If set to `true`, the callback function will be called when building the server bundle.
|
|
268
|
+
|
|
269
|
+
- `client` (optional)
|
|
270
|
+
|
|
271
|
+
**Type**: `boolean`
|
|
272
|
+
|
|
273
|
+
**Default**: `true`
|
|
274
|
+
|
|
275
|
+
If set to `true`, the callback function will be called when building the client bundle.
|
|
276
|
+
|
|
277
|
+
- `prepend` (optional)
|
|
278
|
+
|
|
279
|
+
**Type**: `boolean`
|
|
280
|
+
|
|
281
|
+
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
282
|
+
|
|
283
|
+
### Examples
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
// https://github.com/nuxt-modules/eslint
|
|
287
|
+
import EslintWebpackPlugin from 'eslint-webpack-plugin'
|
|
288
|
+
import { defineNuxtModule, addWebpackPlugin } from '@nuxt/kit'
|
|
289
|
+
|
|
290
|
+
export default defineNuxtModule({
|
|
291
|
+
meta: {
|
|
292
|
+
name: 'nuxt-eslint',
|
|
293
|
+
configKey: 'eslint',
|
|
294
|
+
},
|
|
295
|
+
defaults: nuxt => ({
|
|
296
|
+
include: [`${nuxt.options.srcDir}/**/*.{js,jsx,ts,tsx,vue}`],
|
|
297
|
+
lintOnStart: true,
|
|
298
|
+
}),
|
|
299
|
+
setup(options, nuxt) {
|
|
300
|
+
const webpackOptions = {
|
|
301
|
+
...options,
|
|
302
|
+
context: nuxt.options.srcDir,
|
|
303
|
+
files: options.include,
|
|
304
|
+
lintDirtyModulesOnly: !options.lintOnStart
|
|
305
|
+
}
|
|
306
|
+
addWebpackPlugin(new EslintWebpackPlugin(webpackOptions), { server: false })
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## `addVitePlugin`
|
|
312
|
+
|
|
313
|
+
Append Vite plugin to the config.
|
|
314
|
+
|
|
315
|
+
### Type
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
function addVitePlugin (pluginOrGetter: PluginOrGetter, options?: ExtendViteConfigOptions): void
|
|
319
|
+
|
|
320
|
+
type PluginOrGetter = VitePlugin | VitePlugin[] | (() => VitePlugin | VitePlugin[])
|
|
321
|
+
|
|
322
|
+
interface ExtendViteConfigOptions {
|
|
323
|
+
dev?: boolean
|
|
324
|
+
build?: boolean
|
|
325
|
+
server?: boolean
|
|
326
|
+
client?: boolean
|
|
327
|
+
prepend?: boolean
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
::tip
|
|
332
|
+
See [Vite website](https://vite.dev/guide/api-plugin.html) for more information about Vite plugins. You can also use [this repository](https://github.com/vitejs/awesome-vite#plugins) to find a plugin that suits your needs.
|
|
333
|
+
::
|
|
334
|
+
|
|
335
|
+
### Parameters
|
|
336
|
+
|
|
337
|
+
#### `pluginOrGetter`
|
|
338
|
+
|
|
339
|
+
**Type**: `PluginOrGetter`
|
|
340
|
+
|
|
341
|
+
**Required**: `true`
|
|
342
|
+
|
|
343
|
+
A Vite plugin instance or an array of Vite plugin instances. If a function is provided, it must return a Vite plugin instance or an array of Vite plugin instances.
|
|
344
|
+
|
|
345
|
+
#### `options`
|
|
346
|
+
|
|
347
|
+
**Type**: `ExtendViteConfigOptions`
|
|
348
|
+
|
|
349
|
+
**Default**: `{}`
|
|
350
|
+
|
|
351
|
+
Options to pass to the callback function. This object can have the following properties:
|
|
352
|
+
|
|
353
|
+
- `dev` (optional)
|
|
354
|
+
|
|
355
|
+
**Type**: `boolean`
|
|
356
|
+
|
|
357
|
+
**Default**: `true`
|
|
358
|
+
|
|
359
|
+
If set to `true`, the callback function will be called when building in development mode.
|
|
360
|
+
|
|
361
|
+
- `build` (optional)
|
|
362
|
+
|
|
363
|
+
**Type**: `boolean`
|
|
364
|
+
|
|
365
|
+
**Default**: `true`
|
|
366
|
+
|
|
367
|
+
If set to `true`, the callback function will be called when building in production mode.
|
|
368
|
+
|
|
369
|
+
- `server` (optional)
|
|
370
|
+
|
|
371
|
+
**Type**: `boolean`
|
|
372
|
+
|
|
373
|
+
**Default**: `true`
|
|
374
|
+
|
|
375
|
+
If set to `true`, the callback function will be called when building the server bundle.
|
|
376
|
+
|
|
377
|
+
- `client` (optional)
|
|
378
|
+
|
|
379
|
+
**Type**: `boolean`
|
|
380
|
+
|
|
381
|
+
**Default**: `true`
|
|
382
|
+
|
|
383
|
+
If set to `true`, the callback function will be called when building the client bundle.
|
|
384
|
+
|
|
385
|
+
- `prepend` (optional)
|
|
386
|
+
|
|
387
|
+
**Type**: `boolean`
|
|
388
|
+
|
|
389
|
+
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
390
|
+
|
|
391
|
+
### Examples
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
// https://github.com/yisibell/nuxt-svg-icons
|
|
395
|
+
import { defineNuxtModule, addVitePlugin } from '@nuxt/kit'
|
|
396
|
+
import { svg4VuePlugin } from 'vite-plugin-svg4vue'
|
|
397
|
+
|
|
398
|
+
export default defineNuxtModule({
|
|
399
|
+
meta: {
|
|
400
|
+
name: 'nuxt-svg-icons',
|
|
401
|
+
configKey: 'nuxtSvgIcons',
|
|
402
|
+
},
|
|
403
|
+
defaults: {
|
|
404
|
+
svg4vue: {
|
|
405
|
+
assetsDirName: 'assets/icons',
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
setup(options) {
|
|
409
|
+
addVitePlugin(svg4VuePlugin(options.svg4vue))
|
|
410
|
+
},
|
|
411
|
+
})
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## `addBuildPlugin`
|
|
415
|
+
|
|
416
|
+
Builder-agnostic version of `addWebpackPlugin` and `addVitePlugin`. It will add the plugin to both webpack and vite configurations if they are present.
|
|
417
|
+
|
|
418
|
+
### Type
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
function addBuildPlugin (pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions): void
|
|
422
|
+
|
|
423
|
+
interface AddBuildPluginFactory {
|
|
424
|
+
vite?: () => VitePlugin | VitePlugin[]
|
|
425
|
+
webpack?: () => WebpackPluginInstance | WebpackPluginInstance[]
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
interface ExtendConfigOptions {
|
|
429
|
+
dev?: boolean
|
|
430
|
+
build?: boolean
|
|
431
|
+
server?: boolean
|
|
432
|
+
client?: boolean
|
|
433
|
+
prepend?: boolean
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Parameters
|
|
438
|
+
|
|
439
|
+
#### `pluginFactory`
|
|
440
|
+
|
|
441
|
+
**Type**: `AddBuildPluginFactory`
|
|
442
|
+
|
|
443
|
+
**Required**: `true`
|
|
444
|
+
|
|
445
|
+
A factory function that returns an object with `vite` and/or `webpack` properties. These properties must be functions that return a Vite plugin instance or an array of Vite plugin instances and/or a webpack plugin instance or an array of webpack plugin instances.
|
|
446
|
+
|
|
447
|
+
#### `options`
|
|
448
|
+
|
|
449
|
+
**Type**: `ExtendConfigOptions`
|
|
450
|
+
|
|
451
|
+
**Default**: `{}`
|
|
452
|
+
|
|
453
|
+
Options to pass to the callback function. This object can have the following properties:
|
|
454
|
+
|
|
455
|
+
- `dev` (optional)
|
|
456
|
+
|
|
457
|
+
**Type**: `boolean`
|
|
458
|
+
|
|
459
|
+
**Default**: `true`
|
|
460
|
+
|
|
461
|
+
If set to `true`, the callback function will be called when building in development mode.
|
|
462
|
+
|
|
463
|
+
- `build` (optional)
|
|
464
|
+
|
|
465
|
+
**Type**: `boolean`
|
|
466
|
+
|
|
467
|
+
**Default**: `true`
|
|
468
|
+
|
|
469
|
+
If set to `true`, the callback function will be called when building in production mode.
|
|
470
|
+
|
|
471
|
+
- `server` (optional)
|
|
472
|
+
|
|
473
|
+
**Type**: `boolean`
|
|
474
|
+
|
|
475
|
+
**Default**: `true`
|
|
476
|
+
|
|
477
|
+
If set to `true`, the callback function will be called when building the server bundle.
|
|
478
|
+
|
|
479
|
+
- `client` (optional)
|
|
480
|
+
|
|
481
|
+
**Type**: `boolean`
|
|
482
|
+
|
|
483
|
+
**Default**: `true`
|
|
484
|
+
|
|
485
|
+
If set to `true`, the callback function will be called when building the client bundle.
|
|
486
|
+
|
|
487
|
+
- `prepend` (optional)
|
|
488
|
+
|
|
489
|
+
**Type**: `boolean`
|
|
490
|
+
|
|
491
|
+
If set to `true`, the callback function will be prepended to the array with `unshift()` instead of `push()`.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Examples"
|
|
3
|
+
description: Examples of Nuxt Kit utilities in use.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Accessing Nuxt Vite Config
|
|
7
|
+
|
|
8
|
+
If you are building an integration that needs access to the runtime Vite or webpack config that Nuxt uses, it is possible to extract this using Kit utilities.
|
|
9
|
+
|
|
10
|
+
Some examples of projects doing this already:
|
|
11
|
+
|
|
12
|
+
- [histoire](https://github.com/histoire-dev/histoire/blob/main/packages/histoire-plugin-nuxt/src/index.ts)
|
|
13
|
+
- [nuxt-vitest](https://github.com/danielroe/nuxt-vitest/blob/main/packages/nuxt-vitest/src/config.ts)
|
|
14
|
+
- [@storybook-vue/nuxt](https://github.com/storybook-vue/storybook-nuxt/blob/main/packages/storybook-nuxt/src/preset.ts)
|
|
15
|
+
|
|
16
|
+
Here is a brief example of how you might access the Vite config from a project; you could implement a similar approach to get the webpack configuration.
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { loadNuxt, buildNuxt } from '@nuxt/kit'
|
|
20
|
+
|
|
21
|
+
// https://github.com/nuxt/nuxt/issues/14534
|
|
22
|
+
async function getViteConfig() {
|
|
23
|
+
const nuxt = await loadNuxt({ cwd: process.cwd(), dev: false, overrides: { ssr: false } })
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
|
|
26
|
+
if (isClient) {
|
|
27
|
+
resolve(config)
|
|
28
|
+
throw new Error('_stop_')
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
buildNuxt(nuxt).catch((err) => {
|
|
32
|
+
if (!err.toString().includes('_stop_')) {
|
|
33
|
+
reject(err)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}).finally(() => nuxt.close())
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const viteConfig = await getViteConfig()
|
|
40
|
+
console.log(viteConfig)
|
|
41
|
+
```
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Programmatic Usage"
|
|
3
|
+
description: Nuxt Kit provides a set of utilities to help you work with Nuxt programmatically. These functions allow you to load Nuxt, build Nuxt, and load Nuxt configuration.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/kit/src/loader
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Programmatic usage can be helpful when you want to use Nuxt programmatically, for example, when building a [CLI tool](https://github.com/nuxt/cli) or [test utils](https://github.com/nuxt/nuxt/tree/main/packages/test-utils).
|
|
12
|
+
|
|
13
|
+
## `loadNuxt`
|
|
14
|
+
|
|
15
|
+
Load Nuxt programmatically. It will load the Nuxt configuration, instantiate and return the promise with Nuxt instance.
|
|
16
|
+
|
|
17
|
+
### Type
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
async function loadNuxt (loadOptions?: LoadNuxtOptions): Promise<Nuxt>
|
|
21
|
+
|
|
22
|
+
interface LoadNuxtOptions extends LoadNuxtConfigOptions {
|
|
23
|
+
dev?: boolean
|
|
24
|
+
ready?: boolean
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Parameters
|
|
29
|
+
|
|
30
|
+
#### `loadOptions`
|
|
31
|
+
|
|
32
|
+
**Type**: `LoadNuxtOptions`
|
|
33
|
+
|
|
34
|
+
**Default**: `{}`
|
|
35
|
+
|
|
36
|
+
Loading conditions for Nuxt. `loadNuxt` uses [`c12`](https://github.com/unjs/c12) under the hood, so it accepts the same options as `c12.loadConfig` with some additional options:
|
|
37
|
+
|
|
38
|
+
- `dev` (optional)
|
|
39
|
+
|
|
40
|
+
**Type**: `boolean`
|
|
41
|
+
|
|
42
|
+
**Default**: `false`
|
|
43
|
+
|
|
44
|
+
If set to `true`, Nuxt will be loaded in development mode.
|
|
45
|
+
|
|
46
|
+
- `ready` (optional)
|
|
47
|
+
|
|
48
|
+
**Type**: `boolean`
|
|
49
|
+
|
|
50
|
+
**Default**: `true`
|
|
51
|
+
|
|
52
|
+
If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If set to `false`, you will need to call `nuxt.ready()` to make sure Nuxt is ready to use.
|
|
53
|
+
|
|
54
|
+
## `buildNuxt`
|
|
55
|
+
|
|
56
|
+
Build Nuxt programmatically. It will invoke the builder (currently [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite) or [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)) to bundle the application.
|
|
57
|
+
|
|
58
|
+
### Type
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
async function buildNuxt (nuxt: Nuxt): Promise<any>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Parameters
|
|
65
|
+
|
|
66
|
+
#### `nuxt`
|
|
67
|
+
|
|
68
|
+
**Type**: `Nuxt`
|
|
69
|
+
|
|
70
|
+
**Required**: `true`
|
|
71
|
+
|
|
72
|
+
Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
|
|
73
|
+
|
|
74
|
+
## `loadNuxtConfig`
|
|
75
|
+
|
|
76
|
+
Load Nuxt configuration. It will return the promise with the configuration object.
|
|
77
|
+
|
|
78
|
+
### Type
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
async function loadNuxtConfig (options: LoadNuxtConfigOptions): Promise<NuxtOptions>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Parameters
|
|
85
|
+
|
|
86
|
+
#### `options`
|
|
87
|
+
|
|
88
|
+
**Type**: `LoadNuxtConfigOptions`
|
|
89
|
+
|
|
90
|
+
**Required**: `true`
|
|
91
|
+
|
|
92
|
+
Options to pass in [`c12`](https://github.com/unjs/c12#options) `loadConfig` call.
|
|
93
|
+
|
|
94
|
+
## `writeTypes`
|
|
95
|
+
|
|
96
|
+
Generates `tsconfig.json` and writes it to the project buildDir.
|
|
97
|
+
|
|
98
|
+
### Type
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
function writeTypes (nuxt?: Nuxt): void
|
|
102
|
+
|
|
103
|
+
interface Nuxt {
|
|
104
|
+
options: NuxtOptions
|
|
105
|
+
hooks: Hookable<NuxtHooks>
|
|
106
|
+
hook: Nuxt['hooks']['hook']
|
|
107
|
+
callHook: Nuxt['hooks']['callHook']
|
|
108
|
+
addHooks: Nuxt['hooks']['addHooks']
|
|
109
|
+
ready: () => Promise<void>
|
|
110
|
+
close: () => Promise<void>
|
|
111
|
+
server?: any
|
|
112
|
+
vfs: Record<string, string>
|
|
113
|
+
apps: Record<string, NuxtApp>
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Parameters
|
|
118
|
+
|
|
119
|
+
#### `nuxt`
|
|
120
|
+
|
|
121
|
+
**Type**: `Nuxt`
|
|
122
|
+
|
|
123
|
+
**Required**: `true`
|
|
124
|
+
|
|
125
|
+
Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.
|