@@ -72,6 +72,7 @@ See [live demo](https://codesandbox.io/s/nuxt-components-cou9k) or [video exampl
72
72
### Lazy Imports
73
73
74
74
Nuxt by default does code-splitting per page and components. But sometimes we also need to lazy load them:
75
+
75
76
- Component size is rather big (or has big dependencies imported) like a text-editor
76
77
- Component is rendered conditionally with ` v-if ` or being in a modal
77
78
@@ -88,18 +89,18 @@ You now can easily import a component on-demand:
88
89
</template >
89
90
90
91
<script >
91
- export default {
92
- data () {
93
- return {
94
- foo: null
95
- }
96
- },
97
- methods: {
98
- async loadFoo () {
99
- this .foo = await this .$axios .$get (' foo' )
92
+ export default {
93
+ data () {
94
+ return {
95
+ foo: null
96
+ }
97
+ },
98
+ methods: {
99
+ async loadFoo () {
100
+ this .foo = await this .$axios .$get (' foo' )
101
+ }
100
102
}
101
103
}
102
- }
103
104
</script >
104
105
```
105
106
@@ -127,10 +128,7 @@ For clarity, it is recommended that component file name matches its name. You ca
127
128
If for any reason different prefix is desired, we can add specific directory with the ` prefix ` option: (See [ directories] ( #directories ) section)
128
129
129
130
``` js
130
- components: [
131
- ' ~/components/' ,
132
- { path: ' ~/components/foo/' , prefix: ' foo' }
133
- ]
131
+ components: [' ~/components/' , { path: ' ~/components/foo/' , prefix: ' foo' }]
134
132
```
135
133
136
134
## Overwriting Components
@@ -169,7 +167,7 @@ export default {
169
167
components: [
170
168
' ~/components' , // shortcut to { path: '~/components' }
171
169
{ path: ' ~/components/awesome/' , prefix: ' awesome' }
172
- ],
170
+ ]
173
171
}
174
172
```
175
173
@@ -210,23 +208,21 @@ If you prefer to split your SFCs into `.js`, `.vue` and `.css`, you can only ena
210
208
``` js
211
209
// nuxt.config.js
212
210
export default {
213
- components: [
214
- { path: ' ~/components' , extensions: [' vue' ] }
215
- ]
211
+ components: [{ path: ' ~/components' , extensions: [' vue' ] }]
216
212
}
217
213
```
218
214
219
215
#### pattern
220
216
221
- - Type: ` string ` ([ glob pattern] ( https://github.com/isaacs/node-glob#glob-primer ) )
217
+ - Type: ` string ` ([ glob pattern] ( https://github.com/isaacs/node-glob#glob-primer ) )
222
218
- Default: ` **/*.${extensions.join(',')} `
223
219
224
220
Accept Pattern that will be run against specified ` path ` .
225
221
226
222
#### ignore
227
223
228
224
- Type: ` Array `
229
- - Items: ` string ` ([ glob pattern] ( https://github.com/isaacs/node-glob#glob-primer ) )
225
+ - Items: ` string ` ([ glob pattern] ( https://github.com/isaacs/node-glob#glob-primer ) )
230
226
- Default: ` [] `
231
227
232
228
Ignore patterns that will be run against specified ` path ` .
@@ -244,8 +240,8 @@ Example below adds `awesome-`/`Awesome` prefix to the name of components in `awe
244
240
// nuxt.config.js
245
241
export default {
246
242
components: [
247
- ' ~/components' ,
248
- { path: ' ~/components/awesome/' , prefix: ' awesome' }
243
+ ' ~/components' ,
244
+ { path: ' ~/components/awesome/' , prefix: ' awesome' }
249
245
]
250
246
}
251
247
```
@@ -261,7 +257,7 @@ components/
261
257
<template >
262
258
<div >
263
259
<AwesomeButton >Click on me 🤘</AwesomeButton >
264
- <Button >Click on me</Button >
260
+ <button >Click on me</button >
265
261
</div >
266
262
</template >
267
263
```
@@ -298,7 +294,7 @@ Level are use to define a hint when overwriting the components which have the sa
298
294
export default {
299
295
components: [
300
296
' ~/components' , // default level is 0
301
- { path: ' my-theme/components' , level: 1 }
297
+ { path: ' my-theme/components' , level: 1 }
302
298
]
303
299
}
304
300
```
@@ -314,9 +310,7 @@ These properties are used in production to configure how [components with `Lazy`
314
310
315
311
``` js
316
312
export default {
317
- components: [
318
- { path: ' my-theme/components' , prefetch: true }
319
- ]
313
+ components: [{ path: ' my-theme/components' , prefetch: true }]
320
314
}
321
315
```
322
316
@@ -330,16 +324,23 @@ const componets = {
330
324
}
331
325
```
332
326
327
+ #### isAsync
328
+
329
+ - Type: Boolean
330
+ - Default: ` false ` unless component name ends with ` .async.vue `
331
+
332
+ This flag indicates, component should be loaded async (with a seperate chunk) regardless of using ` Lazy ` prefix or not.
333
+
333
334
## Migration guide
334
335
335
336
## ` v1 ` to ` v2 `
336
337
337
338
Starting with
` [email protected] ` , Nuxt uses
` @nuxt/components ` v2:
338
339
339
340
- All components are globally available so you can move ` components/global/ `
340
- to ` components/ ` and ` global: true ` is not required anymore
341
+ to ` components/ ` and ` global: true ` is not required anymore
341
342
- Full path inside ` components ` is used to prefix component names. If you were structing your
342
- components in multiple directories, should either add prefix or register in ` components ` section of ` nuxt.config ` or use new ` pathPrefix ` option.
343
+ components in multiple directories, should either add prefix or register in ` components ` section of ` nuxt.config ` or use new ` pathPrefix ` option.
343
344
344
345
** Example:**
345
346
@@ -363,7 +364,7 @@ export default {
363
364
' ~/components/templates' ,
364
365
' ~/components/atoms' ,
365
366
' ~/components/molecules' ,
366
- ' ~/components/organisms' ,
367
+ ' ~/components/organisms'
367
368
]
368
369
}
369
370
```
@@ -393,8 +394,8 @@ Then in `awesome-ui/nuxt.js` you can use the `components:dir` hook:
393
394
``` js
394
395
import { join } from ' path'
395
396
396
- export default function () {
397
- this .nuxt .hook (' components:dirs' , ( dirs ) => {
397
+ export default function () {
398
+ this .nuxt .hook (' components:dirs' , dirs => {
398
399
// Add ./components dir to the list
399
400
dirs .push ({
400
401
path: join (__dirname , ' components' ),
@@ -408,10 +409,7 @@ That's it! Now in your project, you can import your ui library as a Nuxt module
408
409
409
410
``` js
410
411
export default {
411
- buildModules: [
412
- ' @nuxt/components' ,
413
- ' awesome-ui/nuxt'
414
- ]
412
+ buildModules: [' @nuxt/components' , ' awesome-ui/nuxt' ]
415
413
}
416
414
```
417
415
@@ -438,15 +436,11 @@ Next: publish your `awesome-ui` module to [npm](https://www.npmjs.com) and share
438
436
439
437
[ npm-version-src ] : https://img.shields.io/npm/v/@nuxt/components/latest.svg?style=flat-square
440
438
[ npm-version-href ] : https://npmjs.com/package/@nuxt/components
441
-
442
439
[ npm-downloads-src ] : https://img.shields.io/npm/dt/@nuxt/components.svg?style=flat-square
443
440
[ npm-downloads-href ] : https://npmjs.com/package/@nuxt/components
444
-
445
441
[ github-actions-ci-src ] : https://img.shields.io/github/workflow/status/nuxt/typescript/test?label=ci&style=flat-square
446
442
[ github-actions-ci-href ] : https://github.com/nuxt/components/actions?query=workflow%3Aci
447
-
448
443
[ codecov-src ] : https://img.shields.io/codecov/c/github/nuxt/components.svg?style=flat-square
449
444
[ codecov-href ] : https://codecov.io/gh/nuxt/components
450
-
451
445
[ license-src ] : https://img.shields.io/npm/l/@nuxt/components.svg?style=flat-square
452
446
[ license-href ] : https://npmjs.com/package/@nuxt/components
0 commit comments