Skip to content

Commit d52304d

Browse files
committed
refactor: simplify component path handling
1 parent 86c176b commit d52304d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/utils/templates.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { gzip } from 'node:zlib'
22
import type { NuxtTemplate } from '@nuxt/schema'
33
import { isAbsolute, join, relative } from 'pathe'
4-
import { genDynamicImport } from 'knitwork'
54
import { compile as jsonSchemaToTypescript } from 'json-schema-to-typescript'
65
import type { JSONSchema } from 'json-schema-to-typescript'
76
import { pascalCase } from 'scule'
@@ -137,13 +136,10 @@ export const componentsManifestTemplate = (manifest: Manifest) => {
137136
return nuxt.options.dev || options.manifest.components.includes(c.pascalName) || c.global
138137
})
139138
.reduce((map, c) => {
140-
map[c.pascalName] = map[c.pascalName] || [
141-
c.pascalName,
142-
`${genDynamicImport(isAbsolute(c.filePath)
143-
? './' + relative(join(nuxt.options.buildDir, 'content'), c.filePath).replace(/\b\.(?!vue)\w+$/g, '')
144-
: c.filePath.replace(/\b\.(?!vue)\w+$/g, ''), { wrapper: false, singleQuotes: true })}`,
145-
c.global,
146-
]
139+
const importPath = isAbsolute(c.filePath)
140+
? './' + relative(join(nuxt.options.buildDir, 'content'), c.filePath).replace(/\b\.(?!vue)\w+$/g, '')
141+
: c.filePath.replace(/\b\.(?!vue)\w+$/g, '')
142+
map[c.pascalName] = map[c.pascalName] || [c.pascalName, importPath, c.global]
147143
return map
148144
}, {} as Record<string, unknown[]>)
149145

@@ -152,7 +148,7 @@ export const componentsManifestTemplate = (manifest: Manifest) => {
152148
const localComponents = componentsList.filter(c => !c[2])
153149
return [
154150
// Export local components directly for SSR compatibility (fixes #3700)
155-
...localComponents.map(([pascalName, type]) => `export { default as ${pascalName} } from ${(type as string).replace(/^import\(/, '').replace(/\)$/, '')}`),
151+
...localComponents.map(([pascalName, path]) => `export { default as ${pascalName} } from '${path}'`),
156152
`export const globalComponents: string[] = ${JSON.stringify(globalComponents)}`,
157153
`export const localComponents: string[] = ${JSON.stringify(localComponents.map(c => c[0]))}`,
158154
].join('\n')

0 commit comments

Comments
 (0)