fix(kit): auto-detect mode from filePath for addComponent (#24835)

This commit is contained in:
Becem 2023-12-20 11:52:14 +01:00 committed by GitHub
parent f5a44fb20a
commit fa3a83924e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,11 @@ export async function addComponent (opts: AddComponentOptions) {
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
nuxt.options.components = nuxt.options.components || []
if (!opts.mode) {
const [, mode = 'all'] = opts.filePath.match(/\.(server|client)(\.\w+)*$/) || []
opts.mode = mode as 'all' | 'client' | 'server'
}
// Apply defaults
const component: Component = {
export: opts.export || 'default',