File tree 2 files changed +14
-11
lines changed
packages/vue-jsx-vapor/src
2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import { transformSync } from '@babel/core'
3
3
import babelTypescript from '@babel/plugin-transform-typescript'
4
4
import jsx from '@vue-jsx-vapor/babel'
5
5
import type { Options } from '../options'
6
- import { registerHMR } from './hmr'
7
6
8
7
export type { Options }
9
8
@@ -12,7 +11,7 @@ export function transformVueJsxVapor(
12
11
id : string ,
13
12
options ?: Options ,
14
13
) {
15
- const result = transformSync ( code , {
14
+ return transformSync ( code , {
16
15
plugins : [
17
16
[ jsx , { compile : options ?. compile , interop : options ?. interop } ] ,
18
17
id . endsWith ( '.tsx' )
@@ -26,12 +25,4 @@ export function transformVueJsxVapor(
26
25
configFile : false ,
27
26
ast : true ,
28
27
} )
29
-
30
- if ( result ) registerHMR ( result , id )
31
-
32
- if ( result ?. code )
33
- return {
34
- code : result . code ,
35
- map : result . map ,
36
- }
37
28
}
Original file line number Diff line number Diff line change 1
1
import Macros from '@vue-jsx-vapor/macros/raw'
2
2
import { createFilter , normalizePath } from 'unplugin-utils'
3
3
import { transformVueJsxVapor } from './core'
4
+ import { registerHMR } from './core/hmr'
4
5
import runtimeCode from './core/runtime?raw'
5
6
import type { Options } from './options'
6
7
import type { UnpluginOptions } from 'unplugin'
@@ -10,6 +11,7 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
10
11
options ?. include || / \. [ c m ] ? [ j t ] s x ? $ / ,
11
12
options ?. exclude ,
12
13
)
14
+ let needHMR = false
13
15
return [
14
16
{
15
17
name : 'vue-jsx-vapor' ,
@@ -30,6 +32,9 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
30
32
} ,
31
33
}
32
34
} ,
35
+ configResolved ( config ) {
36
+ needHMR = config . command === 'serve'
37
+ } ,
33
38
} ,
34
39
resolveId ( id ) {
35
40
if ( normalizePath ( id ) === 'vue-jsx-vapor/runtime' ) return id
@@ -42,7 +47,14 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
42
47
} ,
43
48
transformInclude,
44
49
transform ( code , id ) {
45
- return transformVueJsxVapor ( code , id , options )
50
+ const result = transformVueJsxVapor ( code , id , options )
51
+ if ( result ?. code ) {
52
+ needHMR && registerHMR ( result , id )
53
+ return {
54
+ code : result . code ,
55
+ map : result . map ,
56
+ }
57
+ }
46
58
} ,
47
59
} ,
48
60
...( options . macros === false
You can’t perform that action at this time.
0 commit comments