11import { createHash } from 'node:crypto'
22import path from 'node:path'
3- import type { types } from '@babel/core'
3+ import { types } from '@babel/core'
44import * as babel from '@babel/core'
55import jsx from '@vue/babel-plugin-jsx'
66import { createFilter , normalizePath } from 'vite'
@@ -112,6 +112,36 @@ function vueJsxPlugin(options: Options = {}): Plugin {
112112 } ,
113113 }
114114 } )
115+ } else {
116+ plugins . push ( ( ) => {
117+ return {
118+ visitor : {
119+ ExportDefaultDeclaration : {
120+ enter ( _path : babel . NodePath < types . ExportDefaultDeclaration > ) {
121+ if ( isDefineComponentCall ( _path . node . declaration ) ) {
122+ const declaration = _path . node
123+ . declaration as CallExpression
124+ const nodesPath = _path . replaceWithMultiple ( [
125+ types . variableDeclaration ( 'const' , [
126+ types . variableDeclarator (
127+ types . identifier ( '__default__' ) ,
128+ types . callExpression (
129+ declaration . callee ,
130+ declaration . arguments ,
131+ ) ,
132+ ) ,
133+ ] ) ,
134+ types . exportDefaultDeclaration (
135+ types . identifier ( '__default__' ) ,
136+ ) ,
137+ ] )
138+ _path . scope . registerDeclaration ( nodesPath [ 0 ] )
139+ }
140+ } ,
141+ } ,
142+ } ,
143+ }
144+ } )
115145 }
116146
117147 const result = babel . transformSync ( code , {
@@ -140,7 +170,6 @@ function vueJsxPlugin(options: Options = {}): Plugin {
140170 // check for hmr injection
141171 const declaredComponents : string [ ] = [ ]
142172 const hotComponents : HotComponent [ ] = [ ]
143- let hasDefault = false
144173
145174 for ( const node of result . ast ! . program . body ) {
146175 if ( node . type === 'VariableDeclaration' ) {
@@ -195,7 +224,6 @@ function vueJsxPlugin(options: Options = {}): Plugin {
195224 } )
196225 }
197226 } else if ( isDefineComponentCall ( node . declaration ) ) {
198- hasDefault = true
199227 hotComponents . push ( {
200228 local : '__default__' ,
201229 exported : 'default' ,
@@ -206,14 +234,6 @@ function vueJsxPlugin(options: Options = {}): Plugin {
206234 }
207235
208236 if ( hotComponents . length ) {
209- if ( hasDefault && ( needHmr || ssr ) ) {
210- result . code =
211- result . code ! . replace (
212- / e x p o r t d e f a u l t d e f i n e C o m p o n e n t / g,
213- `const __default__ = defineComponent` ,
214- ) + `\nexport default __default__`
215- }
216-
217237 if ( needHmr && ! ssr && ! / \? v u e & t y p e = s c r i p t / . test ( id ) ) {
218238 let code = result . code
219239 let callbackCode = ``
0 commit comments