diff --git a/packages/nuxt/src/components/plugins/component-names.ts b/packages/nuxt/src/components/plugins/component-names.ts index 5011faaec9..af01adb5dc 100644 --- a/packages/nuxt/src/components/plugins/component-names.ts +++ b/packages/nuxt/src/components/plugins/component-names.ts @@ -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] diff --git a/packages/nuxt/src/components/plugins/loader.ts b/packages/nuxt/src/components/plugins/loader.ts index 5bccd604d4..9e33f4c420 100644 --- a/packages/nuxt/src/components/plugins/loader.ts +++ b/packages/nuxt/src/components/plugins/loader.ts @@ -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() diff --git a/packages/nuxt/src/core/utils/index.ts b/packages/nuxt/src/core/utils/index.ts index 47100a25f6..00974ac965 100644 --- a/packages/nuxt/src/core/utils/index.ts +++ b/packages/nuxt/src/core/utils/index.ts @@ -17,3 +17,4 @@ export function uniqueBy (arr: T[], key: K) { export const QUOTE_RE = /["']/g export const EXTENSION_RE = /\b\.\w+$/g +export const SX_RE = /\.[tj]sx$/