mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 00:52:01 +00:00
feat(nuxt): allow generating metadata for nuxt components (#26204)
This commit is contained in:
parent
2baaab9893
commit
a9effe9c8a
@ -41,6 +41,11 @@ interface ComponentsDir {
|
|||||||
transpile?: 'auto' | boolean
|
transpile?: 'auto' | boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// You can augment this interface (exported from `@nuxt/schema`) if needed
|
||||||
|
interface ComponentMeta {
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
interface Component {
|
interface Component {
|
||||||
pascalName: string
|
pascalName: string
|
||||||
kebabName: string
|
kebabName: string
|
||||||
@ -54,6 +59,7 @@ interface Component {
|
|||||||
island?: boolean
|
island?: boolean
|
||||||
mode?: 'client' | 'server' | 'all'
|
mode?: 'client' | 'server' | 'all'
|
||||||
priority?: number
|
priority?: number
|
||||||
|
meta?: ComponentMeta
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ export async function addComponent (opts: AddComponentOptions) {
|
|||||||
mode: 'all',
|
mode: 'all',
|
||||||
shortPath: opts.filePath,
|
shortPath: opts.filePath,
|
||||||
priority: 0,
|
priority: 0,
|
||||||
|
meta: {},
|
||||||
...opts
|
...opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import type { Component, ComponentsDir, ComponentsOptions } from 'nuxt/schema'
|
|||||||
|
|
||||||
import { distDir } from '../dirs'
|
import { distDir } from '../dirs'
|
||||||
import { clientFallbackAutoIdPlugin } from './client-fallback-auto-id'
|
import { clientFallbackAutoIdPlugin } from './client-fallback-auto-id'
|
||||||
import { componentNamesTemplate, componentsIslandsTemplate, componentsPluginTemplate, componentsTypeTemplate } from './templates'
|
import { componentNamesTemplate, componentsIslandsTemplate, componentsMetadataTemplate, componentsPluginTemplate, componentsTypeTemplate } from './templates'
|
||||||
import { scanComponents } from './scan'
|
import { scanComponents } from './scan'
|
||||||
import { loaderPlugin } from './loader'
|
import { loaderPlugin } from './loader'
|
||||||
import { TreeShakeTemplatePlugin } from './tree-shake'
|
import { TreeShakeTemplatePlugin } from './tree-shake'
|
||||||
@ -127,6 +127,10 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
addTemplate({ filename: 'components.islands.mjs', getContents: () => 'export const islandComponents = {}' })
|
addTemplate({ filename: 'components.islands.mjs', getContents: () => 'export const islandComponents = {}' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (componentOptions.generateMetadata) {
|
||||||
|
addTemplate(componentsMetadataTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
const unpluginServer = createTransformPlugin(nuxt, getComponents, 'server')
|
const unpluginServer = createTransformPlugin(nuxt, getComponents, 'server')
|
||||||
const unpluginClient = createTransformPlugin(nuxt, getComponents, 'client')
|
const unpluginClient = createTransformPlugin(nuxt, getComponents, 'client')
|
||||||
|
|
||||||
|
@ -124,3 +124,9 @@ export const componentNames: string[]
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const componentsMetadataTemplate: NuxtTemplate = {
|
||||||
|
filename: 'components.json',
|
||||||
|
write: true,
|
||||||
|
getContents: ({ app }) => JSON.stringify(app.components, null, 2)
|
||||||
|
}
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
export interface ComponentMeta {
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
export interface Component {
|
export interface Component {
|
||||||
pascalName: string
|
pascalName: string
|
||||||
kebabName: string
|
kebabName: string
|
||||||
@ -9,6 +13,7 @@ export interface Component {
|
|||||||
preload: boolean
|
preload: boolean
|
||||||
global?: boolean | 'sync'
|
global?: boolean | 'sync'
|
||||||
island?: boolean
|
island?: boolean
|
||||||
|
meta?: ComponentMeta
|
||||||
mode?: 'client' | 'server' | 'all'
|
mode?: 'client' | 'server' | 'all'
|
||||||
/**
|
/**
|
||||||
* This number allows configuring the behavior of overriding Nuxt components.
|
* This number allows configuring the behavior of overriding Nuxt components.
|
||||||
@ -114,6 +119,11 @@ export interface ComponentsOptions {
|
|||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
global?: boolean
|
global?: boolean
|
||||||
|
/**
|
||||||
|
* Whether to write metadata to the build directory with information about the components that
|
||||||
|
* are auto-registered in your app.
|
||||||
|
*/
|
||||||
|
generateMetadata?: boolean
|
||||||
loader?: boolean
|
loader?: boolean
|
||||||
|
|
||||||
transform?: {
|
transform?: {
|
||||||
|
Loading…
Reference in New Issue
Block a user