Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/compiler/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -62,6 +63,7 @@ export async function compileSFCTemplate(
typescriptPlugin,
{ isTSX: true, allowExtensions: true },
],
...babelPlugins
],
})

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export interface VitePluginInspectorOptions {
*/
appendTo?: string | RegExp

/**
* user custom babel plugins list, when set, the extra plugins will be append to the default plugins
*/
babelPlugins?: any[]

/**
* Customize openInEditor host (e.g. http://localhost:3000)
* @default false
Expand Down Expand Up @@ -100,6 +105,7 @@ export const DEFAULT_INSPECTOR_OPTIONS: VitePluginInspectorOptions = {
toggleButtonVisibility: 'active',
toggleButtonPos: 'top-right',
appendTo: '',
babelPlugins: [] as any []
openInEditorHost: false,
} as const

Expand Down Expand Up @@ -154,8 +160,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
Expand Down