mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
perf: unify (j/t)sx regex
This commit is contained in:
parent
dc4d032246
commit
ee6f91b7e3
@ -1,13 +1,12 @@
|
||||
import { createUnplugin } from 'unplugin'
|
||||
import MagicString from 'magic-string'
|
||||
import type { Component } from 'nuxt/schema'
|
||||
import { isVue } from '../../core/utils'
|
||||
import { SX_RE, isVue } from '../../core/utils'
|
||||
|
||||
interface NameDevPluginOptions {
|
||||
sourcemap: boolean
|
||||
getComponents: () => Component[]
|
||||
}
|
||||
const NOT_SX_RE = /\.[tj]sx$/
|
||||
const FILENAME_RE = /([^/\\]+)\.\w+$/
|
||||
/**
|
||||
* Set the default name of components to their PascalCase name
|
||||
@ -17,7 +16,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
||||
name: 'nuxt:component-name-plugin',
|
||||
enforce: 'post',
|
||||
transformInclude (id) {
|
||||
return isVue(id) || !!id.match(NOT_SX_RE)
|
||||
return isVue(id) || !!id.match(SX_RE)
|
||||
},
|
||||
transform (code, id) {
|
||||
const filename = id.match(FILENAME_RE)?.[1]
|
||||
|
@ -6,7 +6,7 @@ import { relative } from 'pathe'
|
||||
import type { Component, ComponentsOptions } from 'nuxt/schema'
|
||||
|
||||
import { logger, tryUseNuxt } from '@nuxt/kit'
|
||||
import { isVue, QUOTE_RE } from '../../core/utils'
|
||||
import { SX_RE, QUOTE_RE, isVue } from '../../core/utils'
|
||||
|
||||
interface LoaderOptions {
|
||||
getComponents (): Component[]
|
||||
@ -18,7 +18,6 @@ interface LoaderOptions {
|
||||
}
|
||||
|
||||
const REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE = /(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy(?=[A-Z]))?([^'"]*)["'][^)]*\)/g
|
||||
const NOT_SX_RE = /\.[tj]sx$/
|
||||
export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
||||
const exclude = options.transform?.exclude || []
|
||||
const include = options.transform?.include || []
|
||||
@ -34,7 +33,7 @@ export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
||||
if (include.some(pattern => pattern.test(id))) {
|
||||
return true
|
||||
}
|
||||
return isVue(id, { type: ['template', 'script'] }) || !!id.match(IS_VUE_RE)
|
||||
return isVue(id, { type: ['template', 'script'] }) || !!id.match(SX_RE)
|
||||
},
|
||||
transform (code, id) {
|
||||
const components = options.getComponents()
|
||||
|
@ -17,3 +17,4 @@ export function uniqueBy<T, K extends keyof T> (arr: T[], key: K) {
|
||||
|
||||
export const QUOTE_RE = /["']/g
|
||||
export const EXTENSION_RE = /\b\.\w+$/g
|
||||
export const SX_RE = /\.[tj]sx$/
|
||||
|
Loading…
Reference in New Issue
Block a user