mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
perf(kit): unify mode regex
This commit is contained in:
parent
ee6f91b7e3
commit
f2a9a568b0
@ -3,6 +3,7 @@ import type { Component, ComponentsDir } from '@nuxt/schema'
|
|||||||
import { useNuxt } from './context'
|
import { useNuxt } from './context'
|
||||||
import { assertNuxtCompatibility } from './compatibility'
|
import { assertNuxtCompatibility } from './compatibility'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
import { MODE_RE } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a directory to be scanned for components and imported only when used.
|
* Register a directory to be scanned for components and imported only when used.
|
||||||
@ -19,7 +20,6 @@ export type AddComponentOptions = { name: string, filePath: string } & Partial<E
|
|||||||
'shortPath' | 'async' | 'level' | 'import' | 'asyncImport'
|
'shortPath' | 'async' | 'level' | 'import' | 'asyncImport'
|
||||||
>>
|
>>
|
||||||
|
|
||||||
const COMPONENT_MODE_RE = /\.(server|client)(\.\w+)*$/
|
|
||||||
/**
|
/**
|
||||||
* Register a component by its name and filePath.
|
* Register a component by its name and filePath.
|
||||||
*/
|
*/
|
||||||
@ -29,7 +29,7 @@ export async function addComponent (opts: AddComponentOptions) {
|
|||||||
nuxt.options.components = nuxt.options.components || []
|
nuxt.options.components = nuxt.options.components || []
|
||||||
|
|
||||||
if (!opts.mode) {
|
if (!opts.mode) {
|
||||||
const [, mode = 'all'] = opts.filePath.match(COMPONENT_MODE_RE) || []
|
const [, mode = 'all'] = opts.filePath.match(MODE_RE) || []
|
||||||
opts.mode = mode as 'all' | 'client' | 'server'
|
opts.mode = mode as 'all' | 'client' | 'server'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ import type { NuxtPlugin, NuxtPluginTemplate } from '@nuxt/schema'
|
|||||||
import { useNuxt } from './context'
|
import { useNuxt } from './context'
|
||||||
import { addTemplate } from './template'
|
import { addTemplate } from './template'
|
||||||
import { resolveAlias } from './resolve'
|
import { resolveAlias } from './resolve'
|
||||||
|
import { MODE_RE } from './utils'
|
||||||
|
|
||||||
const PLUGIN_MODE_RE = /\.(server|client)(\.\w+)*$/
|
|
||||||
/**
|
/**
|
||||||
* Normalize a nuxt plugin object
|
* Normalize a nuxt plugin object
|
||||||
*/
|
*/
|
||||||
@ -28,7 +28,7 @@ export function normalizePlugin (plugin: NuxtPlugin | string): NuxtPlugin {
|
|||||||
plugin.mode = 'server'
|
plugin.mode = 'server'
|
||||||
}
|
}
|
||||||
if (!plugin.mode) {
|
if (!plugin.mode) {
|
||||||
const [, mode = 'all'] = plugin.src.match(PLUGIN_MODE_RE) || []
|
const [, mode = 'all'] = plugin.src.match(MODE_RE) || []
|
||||||
plugin.mode = mode as 'all' | 'client' | 'server'
|
plugin.mode = mode as 'all' | 'client' | 'server'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,3 +2,5 @@
|
|||||||
export function toArray<T> (value: T | T[]): T[] {
|
export function toArray<T> (value: T | T[]): T[] {
|
||||||
return Array.isArray(value) ? value : [value]
|
return Array.isArray(value) ? value : [value]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MODE_RE = /\.(server|client)(\.\w+)*$/
|
||||||
|
Loading…
Reference in New Issue
Block a user