From e49dc0c2d3b97bcc6530c81742533c9ec747800b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Mon, 17 Jul 2023 16:48:17 +0800 Subject: [PATCH] feat: add babelPlugins to the plugin options --- packages/core/src/compiler/template.ts | 4 +++- packages/core/src/index.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/compiler/template.ts b/packages/core/src/compiler/template.ts index 33ef714..05ae08d 100644 --- a/packages/core/src/compiler/template.ts +++ b/packages/core/src/compiler/template.ts @@ -15,9 +15,10 @@ interface CompileSFCTemplateOptions { code: string id: string type: 'template' | 'jsx' + babelPlugins?: any[] } export async function compileSFCTemplate( - { code, id, type }: CompileSFCTemplateOptions, + { code, id, type, babelPlugins = [] }: CompileSFCTemplateOptions, ) { const s = new MagicString(code) const relativePath = normalizePath(path.relative(process.cwd(), id)) @@ -62,6 +63,7 @@ export async function compileSFCTemplate( typescriptPlugin, { isTSX: true, allowExtensions: true }, ], + ...babelPlugins ], }) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 00267bc..1056c33 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -70,6 +70,11 @@ export interface VitePluginInspectorOptions { * WARNING: only set this if you know exactly what it does. */ appendTo?: string | RegExp + + /** + * user custom babel plugins list, when set, the extra plugins will be append to the default plugins + */ + babelPlugins?: any[] } const toggleComboKeysMap = { @@ -94,6 +99,7 @@ export const DEFAULT_INSPECTOR_OPTIONS: VitePluginInspectorOptions = { toggleButtonVisibility: 'active', toggleButtonPos: 'top-right', appendTo: '', + babelPlugins: [] as any [] } as const function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPECTOR_OPTIONS): PluginOption { @@ -147,8 +153,9 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE const isJsx = filename.endsWith('.jsx') || filename.endsWith('.tsx') || (filename.endsWith('.vue') && query.isJsx) const isTpl = filename.endsWith('.vue') && query.type !== 'style' && !query.raw + const { babelPlugins } = normalizedOptions if (isJsx || isTpl) - return compileSFCTemplate({ code, id: filename, type: isJsx ? 'jsx' : 'template' }) + return compileSFCTemplate({ code, id: filename, type: isJsx ? 'jsx' : 'template', babelPlugins }) if (!appendTo) return