Skip to content

Commit cab7de4

Browse files
committed
fix(vue-jsx-vapor): prevent register HMR in production environment
1 parent 82a7d68 commit cab7de4

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Diff for: packages/vue-jsx-vapor/src/core/index.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { transformSync } from '@babel/core'
33
import babelTypescript from '@babel/plugin-transform-typescript'
44
import jsx from '@vue-jsx-vapor/babel'
55
import type { Options } from '../options'
6-
import { registerHMR } from './hmr'
76

87
export type { Options }
98

@@ -12,7 +11,7 @@ export function transformVueJsxVapor(
1211
id: string,
1312
options?: Options,
1413
) {
15-
const result = transformSync(code, {
14+
return transformSync(code, {
1615
plugins: [
1716
[jsx, { compile: options?.compile, interop: options?.interop }],
1817
id.endsWith('.tsx')
@@ -26,12 +25,4 @@ export function transformVueJsxVapor(
2625
configFile: false,
2726
ast: true,
2827
})
29-
30-
if (result) registerHMR(result, id)
31-
32-
if (result?.code)
33-
return {
34-
code: result.code,
35-
map: result.map,
36-
}
3728
}

Diff for: packages/vue-jsx-vapor/src/raw.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Macros from '@vue-jsx-vapor/macros/raw'
22
import { createFilter, normalizePath } from 'unplugin-utils'
33
import { transformVueJsxVapor } from './core'
4+
import { registerHMR } from './core/hmr'
45
import runtimeCode from './core/runtime?raw'
56
import type { Options } from './options'
67
import type { UnpluginOptions } from 'unplugin'
@@ -10,6 +11,7 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
1011
options?.include || /\.[cm]?[jt]sx?$/,
1112
options?.exclude,
1213
)
14+
let needHMR = false
1315
return [
1416
{
1517
name: 'vue-jsx-vapor',
@@ -30,6 +32,9 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
3032
},
3133
}
3234
},
35+
configResolved(config) {
36+
needHMR = config.command === 'serve'
37+
},
3338
},
3439
resolveId(id) {
3540
if (normalizePath(id) === 'vue-jsx-vapor/runtime') return id
@@ -42,7 +47,14 @@ const plugin = (options: Options = {}): UnpluginOptions[] => {
4247
},
4348
transformInclude,
4449
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+
}
4658
},
4759
},
4860
...(options.macros === false

0 commit comments

Comments
 (0)