diff --git a/README.md b/README.md index ef0154b..4bbefd4 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,7 @@ interface Options { */ sourceMap?: boolean; - /** @default '**\/*.{vue,jsx.tsx}' */ + /** @default '**\/*.{vue,jsx,tsx}' */ include?: string | RegExp | (string | RegExp)[]; /** @default 'node_modules/**' */ exclude?: string | RegExp | (string | RegExp)[]; diff --git a/src/core/index.ts b/src/core/index.ts index 2788708..d6727a0 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -2,8 +2,8 @@ import { type UnpluginFactory, createUnplugin } from 'unplugin'; import { createFilter } from '@rollup/pluginutils'; import { type ResolvedOptions, type Options } from '../types'; import { TRACE_ID } from './constants'; -import { transform } from './transform'; import { parse_ID } from './parse_ID'; +import { transform } from './transform'; export const unpluginFactory: UnpluginFactory = (options = {}) => { if (process.env.NODE_ENV !== 'development') { @@ -18,16 +18,12 @@ export const unpluginFactory: UnpluginFactory = (options = {}) => { return { name: 'unplugin-vue-source', enforce: 'pre', + transformInclude(id) { - if (filter(id)) { - const parsed = parse_ID(id); - - if (parsed.isSfc) { - const { query } = parsed; - // vue cli | vue-loader - if (query.type === 'template') { - return true; - } + const { file, isSfc, query } = parse_ID(id); + + if (filter(file)) { + if (isSfc && query.type !== 'template') { return ( // vite-plugin-vue !query[TRACE_ID] && @@ -36,6 +32,7 @@ export const unpluginFactory: UnpluginFactory = (options = {}) => { ); } + // vue cli | vue-loader | tsx | jsx return true; } }, @@ -49,7 +46,7 @@ function resolveOptions(opts: Options): ResolvedOptions { return { root: opts.root ?? process.cwd(), sourceMap: opts.sourceMap ?? false, - include: opts.include ?? '**/*.{vue,jsx.tsx}', + include: opts.include ?? '**/*.{vue,jsx,tsx}', exclude: opts.exclude ?? 'node_modules/**', }; } diff --git a/src/types.ts b/src/types.ts index c85d956..5371bc9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ export interface Options { */ sourceMap?: boolean; - /** @default '**\/*.{vue,jsx.tsx}' */ + /** @default '**\/*.{vue,jsx,tsx}' */ include?: string | RegExp | (string | RegExp)[]; /** @default 'node_modules/**' */ exclude?: string | RegExp | (string | RegExp)[];