MCPcopy Index your code
hub / github.com/nuxt/nuxt / handler

Function handler

packages/nuxt/src/components/plugins/transform.ts:72–118  ·  view source on GitHub ↗
(_code, id)

Source from the content-addressed store, hash-verified

70 id: COMPONENT_QUERY_RE,
71 },
72 handler (_code, id) {
73 // Virtual component wrapper
74 const { search } = parseModuleId(id)
75 const params = new URLSearchParams(search)
76 const mode = params.get('nuxt_component')
77 const bare = id.replace(/\?.*/, '')
78 const componentExport = params.get('nuxt_component_export') || 'default'
79 const exportWording = componentExport === 'default' ? 'export default' : `export const ${componentExport} =`
80 if (mode === 'async') {
81 return {
82 code: [
83 'import { defineAsyncComponent } from "vue"',
84 `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r[${JSON.stringify(componentExport)}] || r.default || r))`,
85 ].join('\n'),
86 map: null,
87 }
88 } else if (mode === 'client') {
89 return {
90 code: [
91 genImport(bare, [{ name: componentExport, as: '__component' }]),
92 'import { createClientOnly } from "#app/components/client-only"',
93 `${exportWording} createClientOnly(__component)`,
94 ].join('\n'),
95 map: null,
96 }
97 } else if (mode === 'client,async') {
98 return {
99 code: [
100 'import { defineAsyncComponent } from "vue"',
101 'import { createClientOnly } from "#app/components/client-only"',
102 `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => createClientOnly(r[${JSON.stringify(componentExport)}] || r.default || r)))`,
103 ].join('\n'),
104 map: null,
105 }
106 } else if (mode === 'server' || mode === 'server,async') {
107 const name = params.get('nuxt_component_name')
108 return {
109 code: [
110 `import { createServerComponent } from ${JSON.stringify(options.serverComponentRuntime)}`,
111 `${exportWording} createServerComponent(${JSON.stringify(name)})`,
112 ].join('\n'),
113 map: null,
114 }
115 } else {
116 throw new Error(`Unknown component mode: ${mode}, this might be an internal bug of Nuxt.`)
117 }
118 },
119 },
120 },
121 {

Callers

nothing calls this directly

Calls 3

parseModuleIdFunction · 0.90
getComponentsImportsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…